[FIX] account: on invoice 'refund', keep original salesman and fiscal position
bzr revid: xal@openerp.com-20120306162541-rrt069i9hrr1tp6x
This commit is contained in:
parent
f6c3cd9bb7
commit
05e9ac3295
|
@ -1092,7 +1092,7 @@ class account_invoice(osv.osv):
|
|||
return map(lambda x: (0,0,x), lines)
|
||||
|
||||
def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
|
||||
invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id'])
|
||||
invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id', 'user_id', 'fiscal_position'])
|
||||
obj_invoice_line = self.pool.get('account.invoice.line')
|
||||
obj_invoice_tax = self.pool.get('account.invoice.tax')
|
||||
obj_journal = self.pool.get('account.journal')
|
||||
|
@ -1141,7 +1141,8 @@ class account_invoice(osv.osv):
|
|||
})
|
||||
# take the id part of the tuple returned for many2one fields
|
||||
for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
|
||||
'account_id', 'currency_id', 'payment_term', 'journal_id'):
|
||||
'account_id', 'currency_id', 'payment_term', 'journal_id',
|
||||
'user_id', 'fiscal_position'):
|
||||
invoice[field] = invoice[field] and invoice[field][0]
|
||||
# create the new invoice
|
||||
new_ids.append(self.create(cr, uid, invoice))
|
||||
|
@ -1362,17 +1363,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 +1478,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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue