Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Error when activating "Alerts by products or supplier"

By
Anabela Damas
on 4/15/13, 3:29 PM 2,666 views

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

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/16/13, 3:03 AM

I have made some changes in code. So replace your code by this:

def onchange_sales_order(self, cr, uid, ids, asd_pquotation_id, partner_id, pricelist_id):
    domain = []
    value = []
    warning_message = False
    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'])
            if vals.get('domain', False):
                domain.append(vals['domain'])
            if vals.get('warning', False):
                if not warning_message:
                    warning_message = ""
                warning_message += sol.product_id.default_code + " : " + vals['warning']['message'] + " \n\n "
    res = {'value': {'order_line': value}, 'domain': {'order_line': domain}, 'warning': {'title': 'Warning!', 'message': warning_message}}
    if warning_message:
        res.update({'warning': {'title': 'Warning!', 'message': warning_message}})
    return res

I have modified warning message also because we cannot return multiple warnings.

I get this when I go to Purchases -> Quotation ->Create : "Error: QWeb2 - template['CrashManager.warning']: Runtime Error: TypeError: Cannot read property 'data' of undefined"

Versão Integral, Anabela Damas
on 4/16/13, 6:42 AM

Its working for me. I am not facing such error.

Sudhir Arya (SA)
on 4/16/13, 7:18 AM

Still the same error nothing change.

Versão Integral, Anabela Damas
on 4/16/13, 7:32 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/15/13, 3:29 PM
Seen: 2666 times
Last updated: 3/16/15, 8:10 AM