diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index ed45c705674..be431c9b2e7 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -53,8 +53,8 @@
- - + + @@ -175,7 +175,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 8b1b2a0edda..09e8304340c 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: @@ -1386,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']: diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index dee3d81832b..0e85904dcd7 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): @@ -294,22 +296,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 +1012,22 @@ 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) + 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: + 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) + if result != None: + results.append(result) + return results + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d9acbe17089..dee4da8952e 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 = {} @@ -1146,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 eb902e3058e..e61a810ae6a 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -128,21 +128,21 @@ + 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)"/> diff --git a/addons/sale_layout/sale_layout_view.xml b/addons/sale_layout/sale_layout_view.xml index 6dee4ddd62f..dbea639f86e 100644 --- a/addons/sale_layout/sale_layout_view.xml +++ b/addons/sale_layout/sale_layout_view.xml @@ -22,23 +22,23 @@ 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"/> + 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)"/>