Hi,
I made some customization to OpenErp to when in Purchase Orders(PO) if I choose a Sale Order (SO) the Purchase Order Lines will get the information from Sales Order Lines. My code:
mymodule.py
class purchase_order(osv.osv):
_columns = {
'asd_pquotation_id': fields.many2one('sale.order','Sale Quotation', domain=[('state','in',('draft','sent'))]),
}
_defaults = {
'state': 'draft',
'asd_pquotation_id': lambda self, cr, uid, context: context.get('asd_pquotation_id', False),
}
def onchange_sales_order(self, cr, uid, ids, asd_pquotation_id, partner_id, pricelist_id):
domain = []
value = []
if asd_pquotation_id:
so = self.pool.get('sale.order').browse(cr,uid,asd_pquotation_id)
for sol in so.order_line:
vals = self.pool.get('purchase.order.line').onchange_product_id(cr, uid, ids, pricelist_id, sol.product_id.id, sol.product_uom_qty, sol.product_uom.id, partner_id)
vals['value'].update({
'product_id': sol.product_id.id,
'state':'draft',
'move_ids':[],
'invoiced':0,
'invoice_lines':[]
})
value.append(vals['value'])
domain.append(vals['domain'])
return {'value': {'order_line': value}, 'domain': {'order_line': domain}}
purchase_order()
class sale_order(osv.osv):
_inherit = "sale.order"
_name = "sale.order"
_columns = {
'vi_contact_by': fields.selection([ ('by1','Email'), ('by2','Fax'), ('by3','Phone'), ('by4','Meeting'), ], 'Contacted by'),
'asd_squotation': fields.one2many('purchase.order','asd_pquotation_id', 'Purchase Quotation'),
}
sale_order()
mymoule_view.xml
<record id="purchase_order_form_change" model="ir.ui.view">
<field name="name">purchase.order.form.change</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/group/group/field[@name='company_id']" position="after">
<field name="asd_pquotation_id" on_change="onchange_sales_order(asd_pquotation_id,partner_id,pricelist_id)"/>
</xpath>
</field>
</record>
Everything was working until I check the checkbox in Settins-> Purchases the box from:
Alerts by products or supplier
So if I check this, when I try to choose a SO in the form of PO I get this error:
2013-04-15 17:11:06,423 13876 ERROR nova2 openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
File "/opt/openerp-7.0/openerp/osv/osv.py", line 123, in wrapper
return f(self, dbname, *args, **kwargs)
File "/opt/openerp-7.0/openerp/osv/osv.py", line 179, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/opt/openerp-7.0/openerp/osv/osv.py", line 166, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/opt/openerp-7.0/openerp/addons/infinitechoices/infinitechoices.py", line 74, in onchange_sales_order
domain.append(vals['domain'])
KeyError: 'domain'
2013-04-15 17:11:06,424 13876 ERROR nova2 openerp.netsvc: domain
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 123, in wrapper
return f(self, dbname, *args, **kwargs)
File "/opt/openerp-7.0/openerp/osv/osv.py", line 179, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/opt/openerp-7.0/openerp/osv/osv.py", line 166, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/opt/openerp-7.0/openerp/addons/infinitechoices/infinitechoices.py", line 74, in onchange_sales_order
domain.append(vals['domain'])
KeyError: 'domain'
Someone know how to fix this? Thanks