0

I am newbie in OpenERP. I am working on CRM module. I am creating on Bug module, which is actually inherited by crm_claim. I have put some additional fields(checkboxes into it). Its working fine.
My experience with OpenERP is going very well. But I am stuck at the point of validation. Actually what I want is that user can not save record if no checkbox is clicked. If one of them is clicked it should save the record. I have searched internet. I could not find any sure solution but some ambiguous ones. Here is the list:-
Some posts are suggesting to override write and create. But my question is, I am inheriting from crm_claim, I did not find write and create functions anywhere in hierarchy. If I override them, I have to write all logic to save whole claim and above class as well. Which I feel very difficult.

  1. I tried to find onsave event but I did not find any.
  2. Someone is suggesting wizard to resolve this issue.

I don't know what to do. Kindly help me in this regard.

Dariush Jafari
  • 5,223
  • 7
  • 42
  • 71
noamanfaisal
  • 91
  • 2
  • 11

2 Answers2

0

You do not have to override create or write function. as overriding such a core function is not preferable unless and until you do not have any option .

in this case you have option .

please refer the sale module addons/stock/stock.py

you will find the _constraints, you can use the same . it will check only when selected fields' values will be change. also it have exception raise facility .

Ruchir Shukla
  • 805
  • 6
  • 13
  • What about if you just want a warning: "None checkbox selected. Are you sure?" in a validation popup ? That's my case. The read and write methods can not host call to actions... Do they ? – yucer Sep 11 '13 at 05:08
  • yucel . I think you can write onchange method and return the warning in that case. – Ruchir Shukla Sep 18 '13 at 05:51
-1

The write and create methods are inherited from osv.osv model which is implemented in the BaseModel class in server/openerp/osv/orm.py.

You do not need to to replicate the logic, you just need to call the original method.

For example, in your model, add the following method:

def create(self, cr, uid, vals, context=None):
    """
    Override osv.create() method to validate the data
    """
    if not (vals['attr1'] or vals['attr2'] or vals['attr3']:
        raise osv.except_osv(_('Warning !'),_("You have to choose at least one attribute"))

    return super(my_model, self).create(cr, uid, vals, context)
Mohammad Alhashash
  • 1,543
  • 1
  • 14
  • 30