Why insert a command when clicking the OpenERP button

I am working on a module. it has a button, its name is generated as shown in the following code.

<button name="creates" string="Create" type="object" groups="base.group_erp_manager" />

def creates(self,cr,uid,ids,context=None):
    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
    pr=int(deg_obj.categg_temp)
    ctx=dict(context)
    ctx.update({'default_pr':pr})

    return{
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'product.product',
        'context': ctx,
        'type': 'ir.actions.act_window',
        'target': 'current',
    }

      

when i click this button i get

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: name - name] 

      

On my server I have

2014-12-31 08:18:40,566 7407 ERROR new_db openerp.sql_db: bad query: insert into "product_template" (id,"supply_method","list_price","standard_price","mes_type","uom_id","cost_method","categ_id","uos_coeff","sale_delay","procure_method","sale_ok","company_id","produce_delay","uom_po_id","rental","type",create_uid,create_date,write_uid,write_date) values (639,'buy','1.00','0.00','fixed',1,'standard','9','1.000',7.0,'make_to_stock','True',1,1.0,1,'False','consu',1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC'))
Traceback (most recent call last):
  File "/opt/openerp/server/openerp/sql_db.py", line 226, in execute
    res = self._obj.execute(query, params)
IntegrityError: null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (639, 1, 2014-12-31 08:18:40.463017, 2014-12-31 08:18:40.463017, 1, null, null, 1.00, null, null, null, 0.00, fixed, 1, null, standard, 9, null, 1.000, null, t, null, null, 1, null, 1, 1, f, consu, null, null, 7, null, buy, make_to_stock).

2014-12-31 08:18:40,569 7407 ERROR new_db openerp.netsvc: Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: name - name]
Traceback (most recent call last):
  File "/opt/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 174, in wrapper
    netsvc.abort_response(1, _('Integrity Error'), 'warning', msg)
  File "/opt/openerp/server/openerp/netsvc.py", line 71, in abort_response
    raise openerp.osv.osv.except_osv(description, details)
except_osv: ('Integrity Error', 'The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set\n\n[object with reference: name - name]')

      

My first question. Why am I getting an error with the sql insert command even though there is nothing like the insert associated with the method creates

. It just opens a form where I click the save button or something to save the value. Second, how can I get around this and go to the next step where I can create the item.

NOTE. I have edit, view and buttons methods that just open Value in View and Edit mode. but they have a problem too.

Edit

One thing I must mention. I have print "\n\n Inside Create Method"

 in creating a method. It never shows up on my server console / terminal.

EDIT1 deg_form

has `_inherit = 'product.product'

+3


source to share


1 answer


I'm sure this one _inherit='product.product'

in your class breaks everything.

Your original form (not the one you are trying to open with the button) is trying to save the object before the button's action takes place. As a model, this form deals with the inheritance of product.product, your form tries to use the same in the "product_product" tables (and therefore in the "product_template"). I believe your form does not provide enough fields to satisfy the required "product_template" fields.

Are you sure you need inheritance? It seems to me that you do not need this.



Suggestion: Instead of print () inside your code, try using PDB:

import pdb; pdb.set_trace()

      

It is very powerful and helps with OpenERP.

+1


source







All Articles