diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 32864f9477f..415b6a5d6a2 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -80,8 +80,11 @@ class account_invoice(osv.osv): def _reconciled(self, cr, uid, ids, name, args, context=None): res = {} - for id in ids: - res[id] = self.test_paid(cr, uid, [id]) + wf_service = netsvc.LocalService("workflow") + for inv in self.browse(cr, uid, ids, context=context): + res[inv.id] = self.test_paid(cr, uid, [inv.id]) + if not res[inv.id] and inv.state == 'paid': + wf_service.trg_validate(uid, 'account.invoice', inv.id, 'open_test', cr) return res def _get_reference_type(self, cr, uid, context=None): @@ -1362,17 +1365,6 @@ class account_invoice_line(osv.osv): taxes = res.supplier_taxes_id and res.supplier_taxes_id or (a and self.pool.get('account.account').browse(cr, uid, a, context=context).tax_ids or False) tax_id = fpos_obj.map_tax(cr, uid, fpos, taxes) - if type in ('in_invoice','in_refund') and tax_id and price_unit: - tax_pool = self.pool.get('account.tax') - tax_browse = tax_pool.browse(cr, uid, tax_id) - if not isinstance(tax_browse, list): - tax_browse = [tax_browse] - taxes = tax_pool.compute_inv(cr, uid, tax_browse, price_unit, 1) - tax_amount = reduce(lambda total, tax_dict: total + tax_dict.get('amount', 0.0), taxes, 0.0) - price_unit = price_unit - tax_amount - if qty != 0: - price_unit = price_unit / float(qty) - if type in ('in_invoice', 'in_refund'): result.update( {'price_unit': price_unit or res.standard_price,'invoice_line_tax_id': tax_id} ) else: @@ -1488,13 +1480,19 @@ class account_invoice_line(osv.osv): # # Set the tax field according to the account and the fiscal position # - def onchange_account_id(self, cr, uid, ids, fposition_id, account_id): + def onchange_account_id(self, cr, uid, ids, product_id, partner_id, inv_type, fposition_id, account_id): if not account_id: return {} taxes = self.pool.get('account.account').browse(cr, uid, account_id).tax_ids fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False - res = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes) - return {'value':{'invoice_line_tax_id': res}} + tax_ids = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes) + + product_change_result = self.product_id_change(cr, uid, ids, product_id, False, type=inv_type, + partner_id=partner_id, fposition_id=fposition_id) + unique_tax_ids = set(tax_ids) + if product_change_result and 'value' in product_change_result and 'invoice_line_tax_id' in product_change_result['value']: + unique_tax_ids |= set(product_change_result['value']['invoice_line_tax_id']) + return {'value':{'invoice_line_tax_id': list(unique_tax_ids)}} account_invoice_line()