3

I am working on module. it has a button, its name is creates, as shown in 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 log 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 is. Why I am getting an error with sql insert command although there is nothing like insert related to creates method. It simply opens a form where i will press save button or something to save value. Secondly, how i can bypass this and move to next step where i can create item.

NOTE: I have Edit, View methods and buttons too, which simply opens Value in View and Edit mode. but have same issue with them too.

Edit

One thing i must mention. I have print "\n\n Inside Create Method" in creater method. It is never shown on my server console/terminal.

EDIT1 deg_form has `_inherit= 'product.product'

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76

1 Answers1

1

I'm pretty sure that this _inherit='product.product' in your class is breaking the things.

Your original form (not the one you try to open with the button) is trying to save the object before executing the button's action. As the model this form is dealing with inherits 'product.product', your form is trying to same something in the 'product_product' (and respectively - in 'product_template') tables. I suppose that your form does not supply enough fields to satisfy the required 'product_template' fields.

Are you sure you need the inheritance? It seems to me that you don't need it.

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

import pdb; pdb.set_trace()

It's very powerful and helps a lot with OpenERP.

Andrei Boyanov
  • 2,309
  • 15
  • 18