From b550fd58f21ebf46d26c4d8991d33f95d46e02b8 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 11:20:57 +0200 Subject: [PATCH 1/7] [imp] implemented correct behavior for onchange_price and its one2many bzr revid: nicolas.vanhoren@openerp.com-20110630092057-ysv11h7ntrb7j3yi --- addons/account_voucher/account_voucher.py | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index b4422cd8051..7761425c94f 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -294,22 +294,24 @@ class account_voucher(osv.osv): return True def onchange_price(self, cr, uid, ids, line_ids, tax_id, partner_id=False, context=None): + context = context or {} tax_pool = self.pool.get('account.tax') partner_pool = self.pool.get('res.partner') position_pool = self.pool.get('account.fiscal.position') + line_pool = self.pool.get('account.voucher.line') res = { 'tax_amount': False, 'amount': False, } voucher_total = 0.0 - voucher_line_ids = [] + + line_ids = resolve_o2m_operations(cr, uid, line_pool, line_ids, ["amount"], context) total = 0.0 total_tax = 0.0 for line in line_ids: line_amount = 0.0 - line_amount = line[2] and line[2].get('amount',0.0) or 0.0 - voucher_line_ids += [line[1]] + line_amount = line.get('amount',0.0) voucher_total += line_amount total = voucher_total @@ -1008,4 +1010,21 @@ class account_bank_statement_line(osv.osv): account_bank_statement_line() +def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): + results = [] + for operation in operations: + result = None + if not isinstance(operation, (list, tuple)): + result = target_osv.read(cr, uid, operation, fields, context=context) + if operation[0] == 0: + # may be necessary to check if all the fields are here and get the default values? + result = operation[2] + elif operation[0] == 1: + result = target_osv.read(cr, uid, operation[1], fields, context=context) + result.update(operation[2]) + elif operation[0] == 4: + result = target_osv.read(cr, uid, operation[1], fields, context=context) + results.append(result) + return results + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From d40da9c9d6b0de71c96b3f66ae95cdd477b3c053 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 11:42:13 +0200 Subject: [PATCH 2/7] [fix] small potential error that will never in this case anyway bzr revid: nicolas.vanhoren@openerp.com-20110630094213-oioei7gyxz1rfi50 --- addons/account_voucher/account_voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 7761425c94f..f8816ee3f09 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1016,7 +1016,7 @@ def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): result = None if not isinstance(operation, (list, tuple)): result = target_osv.read(cr, uid, operation, fields, context=context) - if operation[0] == 0: + elif operation[0] == 0: # may be necessary to check if all the fields are here and get the default values? result = operation[2] elif operation[0] == 1: From 951e10382be3f3ef8ac71693a8df310a913c5ac2 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 12:19:04 +0200 Subject: [PATCH 3/7] [imp] changed o2m in customer payment too bzr revid: nicolas.vanhoren@openerp.com-20110630101904-23cwohgh57pzjdjo --- addons/account_voucher/account_voucher.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index f8816ee3f09..fe284213f6e 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -150,11 +150,13 @@ class account_voucher(osv.osv): credit += l['amount'] return abs(amount - abs(credit - debit)) - def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount): + def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount, context=None): + context = context or {} if not line_dr_ids and not line_cr_ids: return {'value':{}} - line_dr_ids = [x[2] for x in line_dr_ids] - line_cr_ids = [x[2] for x in line_cr_ids] + line_osv = self.pool.get("account.voucher.line") + line_dr_ids = resolve_o2m_operations(cr, uid, line_osv, line_dr_ids, ['amount'], context) + line_cr_ids = resolve_o2m_operations(cr, uid, line_osv, line_cr_ids, ['amount'], context) return {'value': {'writeoff_amount': self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount)}} def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None): @@ -1024,7 +1026,8 @@ def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): result.update(operation[2]) elif operation[0] == 4: result = target_osv.read(cr, uid, operation[1], fields, context=context) - results.append(result) + if result != None: + results.append(result) return results # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 4a00aefa4db1cca78cbb937d28f094b6762a28f1 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 1 Jul 2011 17:12:37 +0200 Subject: [PATCH 4/7] [fix] cleaned on_change product_id in sale bzr revid: nicolas.vanhoren@openerp.com-20110701151237-lkmtrp60digfi7f6 --- addons/sale/sale.py | 4 +++- addons/sale/sale_view.xml | 6 +++--- addons/sale_layout/sale_layout_view.xml | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 0b436f0dc91..64faca26e77 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1013,7 +1013,9 @@ class sale_order_line(osv.osv): def product_id_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, - lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False): + lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None): + context = context or {} + lang = lang or ('lang' in context and context['lang']) if not partner_id: raise osv.except_osv(_('No Customer Defined !'), _('You have to select a customer in the sales form !\nPlease set one customer before choosing a product.')) warning = {} diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 6c444ad174d..14d3046e885 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -128,12 +128,12 @@ @@ -142,7 +142,7 @@ diff --git a/addons/sale_layout/sale_layout_view.xml b/addons/sale_layout/sale_layout_view.xml index 6dee4ddd62f..4b69a01d919 100644 --- a/addons/sale_layout/sale_layout_view.xml +++ b/addons/sale_layout/sale_layout_view.xml @@ -22,13 +22,13 @@ context="{'partner_id':parent.partner_id,'quantity':product_uom_qty,'pricelist':parent.pricelist_id,'shop':parent.shop_id,'uom':product_uom}" name="product_id" attrs="{'readonly':[('layout_type','!=','article')]}" - on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, 'lang' in context and context['lang'], True, parent.date_order, product_packaging, parent.fiscal_position)" + on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False, context)" select="1"/> From f418321fd434ae7fbc2f8dfe396c58a783709c6d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 1 Jul 2011 17:13:48 +0200 Subject: [PATCH 5/7] [fix] cleaned on_change product_uom in sale bzr revid: nicolas.vanhoren@openerp.com-20110701151348-gl6aoxrfy97ow80m --- addons/sale/sale.py | 4 +++- addons/sale/sale_view.xml | 2 +- addons/sale_layout/sale_layout_view.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 64faca26e77..fd2dddbe309 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1148,7 +1148,9 @@ class sale_order_line(osv.osv): def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, - lang=False, update_tax=True, date_order=False): + lang=False, update_tax=True, date_order=False, context=None): + context = context or {} + lang = lang or ('lang' in context and context['lang']) res = self.product_id_change(cursor, user, ids, pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax, diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 14d3046e885..28201cfaa76 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -136,7 +136,7 @@ on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, product_packaging, parent.fiscal_position, True, context)" /> + on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/> + on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/> Date: Mon, 4 Jul 2011 16:14:10 +0200 Subject: [PATCH 6/7] [fix] changed product_id_change in account.invoice.line bzr revid: nicolas.vanhoren@openerp.com-20110704141410-h7ecesw5aduo0kbd --- addons/account/account_invoice_view.xml | 4 ++-- addons/account/invoice.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index ed45c705674..cd1f41af3dc 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -53,7 +53,7 @@
- + @@ -175,7 +175,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 8b1b2a0edda..712d000b02e 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -1312,10 +1312,12 @@ class account_invoice_line(osv.osv): res['arch'] = etree.tostring(doc) return res - def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): + def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): if context is None: context = {} - company_id = context.get('company_id',False) + company_id = company_id if company_id != None else context.get('company_id',False) + context = dict(context) + context.update({'company_id': company_id}) if not partner_id: raise osv.except_osv(_('No Partner Defined !'),_("You must first select a partner !") ) if not product: From fa3016fd4e853242a3102203b541d9f44bff2f2d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 4 Jul 2011 16:16:07 +0200 Subject: [PATCH 7/7] [fix] changed uos_id_change in account.invoice.line bzr revid: nicolas.vanhoren@openerp.com-20110704141607-dj6hkda8yv46pr8y --- addons/account/account_invoice_view.xml | 2 +- addons/account/invoice.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index cd1f41af3dc..be431c9b2e7 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -54,7 +54,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 712d000b02e..09e8304340c 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -1388,7 +1388,12 @@ class account_invoice_line(osv.osv): res_final['value']['price_unit'] = new_price return res_final - def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): + def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): + if context is None: + context = {} + company_id = company_id if company_id != None else context.get('company_id',False) + context = dict(context) + context.update({'company_id': company_id}) warning = {} res = self.product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context=context) if 'uos_id' in res['value']: