This question has been flagged

Hi, I had a new state to Sale Quotation, and two other states to Purchase quotation. Now I needed to when changing the state in Purchase order to automatically change the state of Sale quotation from draft to my new state.

I don't have any idea if this change is in the file mymodule_workflow.xml or in mymodule.py, I've tried in both but nothing...

In mymodule_workflow.xml I've tried this:

....
    <record id="trans_receivepq_waitingdocs" model="workflow.transition">
        <field name="act_from" ref="sale.act_draft"/>
        <field name="act_to" ref="act_waitingdocs"/>
        <field name="signal">purchase_received</field>
    </record>
....

and after I've tried this:

   <record id="act_rfq_received" model="workflow.activity">
        <field name="wkf_id" ref="purchase.purchase_order"/>
        <field name="name">received</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'received'})</field>
    </record>
    <record id="act_po_recpq" model="workflow.activity">
        <field name="wkf_id" ref="purchase.purchase_order"/>
        <field name="name">po_recpq</field>
        <field name="kind">subflow</field>
        <field name="subflow_id" search="[('osv','=','sale.order')]"/>
        <field name="action">write({'state':'waitingdocs'})</field>
    </record>
    <record id="trans_sent_received" model="workflow.transition">
        <field name="act_from" ref="purchase.act_sent"/>
        <field name="act_to" ref="act_rfq_received"/>
        <field name="signal">purchase_received</field>
    </record>
    <record id="trans_sent_received_so" model="workflow.transition">
        <field name="act_from" ref="purchase.act_sent"/>
        <field name="act_to" ref="act_po_recpq"/>
        <field name="signal">purchase_received</field>
    </record>

But nothing happens, no error no nothing...

Then I've tried like this in mymodule.py :

def contracts_received(self, cr, uid, ids, context=None, default=None):
    so = {}
    soid = {}
    if not default:
        default = {}
    soid = default.get('asd_pquotation_id')
    so = self.pool.get('sale.order').browse(cr,uid,soid)
    so.write(cr, uid, ids, {'state':'waitingdocs'})
    self.write(cr, uid, ids, {'state':'received'}, context=context)
    return True

and in mymodule_workflow.xml :

<record id="act_rfq_received" model="workflow.activity">
    <field name="wkf_id" ref="purchase.purchase_order"/>
    <field name="name">received</field>
    <field name="kind">function</field>
    <field name="action">contracts_received()</field>
</record>

This way I've this error :

 WARNING teste28maio1458 openerp.osv.orm: No such field(s) in model purchase.order.line: code, date, so_calc_id, supplier_id, client_number, namecalc, image, quantity.
2013-05-30 16:13:03,052 16600 ERROR teste28maio1458 openerp.sql_db: bad query: insert into "purchase_order_line" (id,"product_uom","order_id","price_unit","product_qty","partner_id","invoiced","date_planned","company_id","name","state","product_id","account_analytic_id",create_uid,create_date,write_uid,write_date) values (20,5,20,'30.00','1.000','5','False','2013-05-30 00:00:00',NULL,'Service',NULL,1,NULL,1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC'))
Traceback (most recent call last):
  File "/opt/openerp-7.0/openerp/sql_db.py", line 227, in execute
    res = self._obj.execute(query, params)
IntegrityError: null value in column "state" violates not-null constraint

2013-05-30 16:13:03,055 16600 ERROR teste28maio1458 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: state - state]
Traceback (most recent call last):
  File "/opt/openerp-7.0/openerp/netsvc.py", line 289, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp-7.0/openerp/service/web_services.py", line 614, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp-7.0/openerp/osv/osv.py", line 169, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp-7.0/openerp/osv/osv.py", line 153, in wrapper
    netsvc.abort_response(1, _('Integrity Error'), 'warning', msg)
  File "/opt/openerp-7.0/openerp/netsvc.py", line 72, 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: state - state]')

Thanks

Avatar
Discard