[FIX] account: exchange rate uses invoice date instead of server date
When an invoice is created, the exchange rate used takes into account the invoice date instead of the server date. opw: 631749
This commit is contained in:
@@ -1301,7 +1301,7 @@ class account_invoice_line(models.Model):
|
||||
@api.multi
|
||||
def product_id_change(self, product, uom_id, qty=0, name='', type='out_invoice',
|
||||
partner_id=False, fposition_id=False, price_unit=False, currency_id=False,
|
||||
company_id=None):
|
||||
company_id=None, date_invoice=None):
|
||||
context = self._context
|
||||
company_id = company_id if company_id is not None else context.get('company_id', False)
|
||||
self = self.with_context(company_id=company_id, force_company=company_id)
|
||||
@@ -1359,7 +1359,7 @@ class account_invoice_line(models.Model):
|
||||
if company.currency_id != currency:
|
||||
if type in ('in_invoice', 'in_refund'):
|
||||
values['price_unit'] = product.standard_price
|
||||
values['price_unit'] = values['price_unit'] * currency.rate
|
||||
values['price_unit'] = values['price_unit'] * currency.with_context(dict(context or {}, date=date_invoice)).rate
|
||||
|
||||
if values['uos_id'] and values['uos_id'] != product.uom_id.id:
|
||||
values['price_unit'] = self.env['product.uom']._compute_price(
|
||||
@@ -1369,14 +1369,14 @@ class account_invoice_line(models.Model):
|
||||
|
||||
@api.multi
|
||||
def uos_id_change(self, product, uom, qty=0, name='', type='out_invoice', partner_id=False,
|
||||
fposition_id=False, price_unit=False, currency_id=False, company_id=None):
|
||||
fposition_id=False, price_unit=False, currency_id=False, company_id=None, date_invoice=None):
|
||||
context = self._context
|
||||
company_id = company_id if company_id != None else context.get('company_id', False)
|
||||
self = self.with_context(company_id=company_id)
|
||||
|
||||
result = self.product_id_change(
|
||||
product, uom, qty, name, type, partner_id, fposition_id, price_unit,
|
||||
currency_id, company_id=company_id,
|
||||
currency_id, company_id=company_id, date_invoice=date_invoice
|
||||
)
|
||||
warning = {}
|
||||
if not uom:
|
||||
@@ -1451,7 +1451,7 @@ class account_invoice_line(models.Model):
|
||||
# Set the tax field according to the account and the fiscal position
|
||||
#
|
||||
@api.multi
|
||||
def onchange_account_id(self, product_id, partner_id, inv_type, fposition_id, account_id):
|
||||
def onchange_account_id(self, product_id, partner_id, inv_type, fposition_id, account_id, date_invoice=None):
|
||||
if not account_id:
|
||||
return {}
|
||||
unique_tax_ids = []
|
||||
@@ -1461,7 +1461,7 @@ class account_invoice_line(models.Model):
|
||||
unique_tax_ids = fpos.map_tax(account.tax_ids).ids
|
||||
else:
|
||||
product_change_result = self.product_id_change(product_id, False, type=inv_type,
|
||||
partner_id=partner_id, fposition_id=fposition_id, company_id=account.company_id.id)
|
||||
partner_id=partner_id, fposition_id=fposition_id, company_id=account.company_id.id, date_invoice=date_invoice)
|
||||
if 'invoice_line_tax_id' in product_change_result.get('value', {}):
|
||||
unique_tax_ids = product_change_result['value']['invoice_line_tax_id']
|
||||
return {'value': {'invoice_line_tax_id': unique_tax_ids}}
|
||||
|
||||
@@ -60,18 +60,18 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="product_id"
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)" context="{'partner_id': parent.partner_id}"/>
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)" context="{'partner_id': parent.partner_id}"/>
|
||||
<label for="quantity"/>
|
||||
<div>
|
||||
<field name="quantity" class="oe_inline"/>
|
||||
<field name="uos_id" class="oe_inline" groups="product.group_uom"
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)"/>
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/>
|
||||
</div>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="sale.group_discount_per_so_line"/>
|
||||
</group>
|
||||
<group>
|
||||
<field domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id" on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id)" groups="account.group_account_user"/>
|
||||
<field domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id" on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id, parent.date_invoice)" groups="account.group_account_user"/>
|
||||
<field name="invoice_line_tax_id" context="{'type':parent.get('type')}" domain="[('parent_id','=',False),('company_id', '=', parent.company_id)]" widget="many2many_tags"/>
|
||||
<field domain="[('type','<>','view'), ('company_id', '=', parent.company_id)], ('state','not in',('close','cancelled'))]" name="account_analytic_id" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="company_id" groups="base.group_multi_company" readonly="1"/>
|
||||
@@ -209,17 +209,17 @@
|
||||
<tree string="Invoice lines" editable="bottom">
|
||||
<field name="sequence" widget="handle" />
|
||||
<field name="product_id"
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)" context="{'partner_id': parent.partner_id}"/>
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)" context="{'partner_id': parent.partner_id}"/>
|
||||
<field name="name"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="account_id" groups="account.group_account_user"
|
||||
domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '=', 'other')]"
|
||||
on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id)"/>
|
||||
on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id, parent.date_invoice)"/>
|
||||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"
|
||||
domain="[('type','!=','view'), ('company_id', '=', parent.company_id), ('state','not in',('close','cancelled'))]"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uos_id" groups="product.group_uom"
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)"/>
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="sale.group_discount_per_so_line"/>
|
||||
<field name="invoice_line_tax_id" widget="many2many_tags" context="{'type':parent.type}"
|
||||
@@ -367,17 +367,17 @@
|
||||
<tree string="Invoice Lines" editable="bottom">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="product_id"
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)"/>
|
||||
on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/>
|
||||
<field name="name"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="account_id" groups="account.group_account_user"
|
||||
domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '=', 'other')]"
|
||||
on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id)"/>
|
||||
on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id, parent.date_invoice)"/>
|
||||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"
|
||||
domain="[('type','!=','view'), ('company_id', '=', parent.company_id), ('state','not in',('close','cancelled'))]"/>
|
||||
<field name="quantity"/>
|
||||
<field name="uos_id" groups="product.group_uom"
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, context)"/>
|
||||
on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount" groups="sale.group_discount_per_so_line"/>
|
||||
<field name="invoice_line_tax_id" widget="many2many_tags" context="{'type':parent.type}"
|
||||
|
||||
@@ -76,8 +76,8 @@ class account_invoice_line(osv.osv):
|
||||
_inherit = "account.invoice.line"
|
||||
_description = "Invoice Line"
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, context=None):
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id=currency_id, company_id=company_id, context=context)
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, date_invoice=None, context=None):
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id=currency_id, company_id=company_id, date_invoice=date_invoice, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), company_id=company_id, context=context)
|
||||
if rec:
|
||||
res_prod['value'].update({'account_analytic_id': rec.analytic_id.id})
|
||||
|
||||
@@ -303,8 +303,8 @@ class account_invoice_line(osv.osv):
|
||||
res ['analytics_id'] = line.analytics_id and line.analytics_id.id or False
|
||||
return res
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, context=None):
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id, company_id=company_id, context=context)
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, date_invoice=None, context=None):
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id, company_id=company_id, date_invoice=date_invoice, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context=context)
|
||||
if rec and rec.analytics_id:
|
||||
res_prod['value'].update({'analytics_id': rec.analytics_id.id})
|
||||
|
||||
@@ -43,9 +43,9 @@ class account_invoice_line(osv.osv):
|
||||
return res
|
||||
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, context=None):
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, date_invoice=None, context=None):
|
||||
fiscal_pool = self.pool.get('account.fiscal.position')
|
||||
res = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id, company_id, context)
|
||||
res = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id, company_id, date_invoice, context)
|
||||
if not product:
|
||||
return res
|
||||
if type in ('in_invoice','in_refund'):
|
||||
|
||||
Reference in New Issue
Block a user