[IMP] analytic: clean account semantics
When installing account module, some field semantic on AAL changed. Indeed this module modify some concept for its own use cases. Since analytic accounting is only used inside the company, there is no interess to have the amounts stored in both currencies. So the fields amount_currency, analytic_amount_currency and company_currency_id can be removed. Doing that, we remove the unfair related of account module.
This commit is contained in:
@@ -9,25 +9,15 @@ class AccountAnalyticLine(models.Model):
|
||||
_description = 'Analytic Line'
|
||||
_order = 'date desc'
|
||||
|
||||
amount = fields.Monetary(currency_field='company_currency_id')
|
||||
product_uom_id = fields.Many2one('product.uom', string='Unit of Measure')
|
||||
product_id = fields.Many2one('product.product', string='Product')
|
||||
general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', readonly=True,
|
||||
general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', readonly=True,
|
||||
related='move_id.account_id', store=True, domain=[('deprecated', '=', False)])
|
||||
move_id = fields.Many2one('account.move.line', string='Move Line', ondelete='cascade', index=True)
|
||||
code = fields.Char(size=8)
|
||||
ref = fields.Char(string='Ref.')
|
||||
company_currency_id = fields.Many2one('res.currency', related='company_id.currency_id', readonly=True,
|
||||
help='Utility field to express amount currency')
|
||||
currency_id = fields.Many2one('res.currency', related='move_id.currency_id', string='Account Currency', store=True, help="The related account currency if not equal to the company one.", readonly=True)
|
||||
amount_currency = fields.Monetary(related='move_id.amount_currency', store=True, help="The amount expressed in the related account currency if not equal to the company one.", readonly=True)
|
||||
analytic_amount_currency = fields.Monetary(string='Amount Currency', compute="_get_analytic_amount_currency", help="The amount expressed in the related account currency if not equal to the company one.", readonly=True)
|
||||
partner_id = fields.Many2one('res.partner', related='account_id.partner_id', string='Partner', store=True, readonly=True)
|
||||
|
||||
def _get_analytic_amount_currency(self):
|
||||
for line in self:
|
||||
line.analytic_amount_currency = abs(line.amount_currency) * copysign(1, line.amount)
|
||||
|
||||
@api.v8
|
||||
@api.onchange('product_id', 'product_uom_id', 'unit_amount', 'currency_id')
|
||||
def on_change_unit_amount(self):
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
<field name="move_id" readonly="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='amount']" position="after">
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
<field name="amount_currency" invisible="1"/>
|
||||
<field name="analytic_amount_currency"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_uom_id" class="oe_inline"/>
|
||||
</xpath>
|
||||
|
||||
@@ -68,8 +68,8 @@ class AccountAnalyticLine(models.Model):
|
||||
|
||||
# Prevent unnecessary currency conversion that could be impacted by exchange rate
|
||||
# fluctuations
|
||||
if self.currency_id and self.amount_currency and self.currency_id == order.currency_id:
|
||||
return abs(self.amount_currency / self.unit_amount)
|
||||
if self.currency_id and self.amount and self.currency_id == order.currency_id:
|
||||
return abs(self.amount / self.unit_amount)
|
||||
|
||||
price_unit = abs(self.amount / self.unit_amount)
|
||||
currency_id = self.company_id.currency_id
|
||||
|
||||
@@ -14,7 +14,7 @@ class AccountAnalyticLine(models.Model):
|
||||
('non_billable', 'Non Billable'),
|
||||
('non_billable_project', 'No task found')], string="Billable Type", readonly=True, copy=False)
|
||||
timesheet_invoice_id = fields.Many2one('account.invoice', string="Invoice", readonly=True, copy=False, help="Invoice created from the timesheet")
|
||||
timesheet_revenue = fields.Monetary("Revenue", default=0.0, readonly=True, currency_field='company_currency_id', copy=False)
|
||||
timesheet_revenue = fields.Monetary("Revenue", default=0.0, readonly=True, copy=False)
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
|
||||
@@ -67,17 +67,17 @@ class AccountInvoice(models.Model):
|
||||
if invoice_line.product_id.invoice_policy == 'delivery':
|
||||
invoiced_price_per_hour = invoice_line.currency_id.round(invoice_line.price_subtotal / float(sum(uninvoiced_timesheet_lines.mapped('unit_amount'))))
|
||||
# invoicing analytic lines of different currency
|
||||
total_revenue_per_currency = dict.fromkeys(uninvoiced_timesheet_lines.mapped('company_currency_id').ids, 0.0)
|
||||
total_revenue_per_currency = dict.fromkeys(uninvoiced_timesheet_lines.mapped('currency_id').ids, 0.0)
|
||||
for index, timesheet_line in enumerate(uninvoiced_timesheet_lines.sorted(key=lambda ts: (ts.date, ts.id))):
|
||||
if index+1 != len(uninvoiced_timesheet_lines):
|
||||
line_revenue = invoice_line.currency_id.compute(invoiced_price_per_hour, timesheet_line.company_currency_id) * timesheet_line.unit_amount
|
||||
total_revenue_per_currency[timesheet_line.company_currency_id.id] += line_revenue
|
||||
line_revenue = invoice_line.currency_id.compute(invoiced_price_per_hour, timesheet_line.currency_id) * timesheet_line.unit_amount
|
||||
total_revenue_per_currency[timesheet_line.currency_id.id] += line_revenue
|
||||
else: # last line: add the difference to avoid rounding problem
|
||||
total_revenue = sum([self.env['res.currency'].browse(currency_id).compute(amount, timesheet_line.company_currency_id) for currency_id, amount in total_revenue_per_currency.items()])
|
||||
line_revenue = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.company_currency_id) - total_revenue
|
||||
total_revenue = sum([self.env['res.currency'].browse(currency_id).compute(amount, timesheet_line.currency_id) for currency_id, amount in total_revenue_per_currency.items()])
|
||||
line_revenue = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.currency_id) - total_revenue
|
||||
timesheet_line.write({
|
||||
'timesheet_invoice_id': invoice.id,
|
||||
'timesheet_revenue': timesheet_line.company_currency_id.round(line_revenue),
|
||||
'timesheet_revenue': timesheet_line.currency_id.round(line_revenue),
|
||||
})
|
||||
|
||||
# ordered : update revenue with the prorata of theorical revenue
|
||||
@@ -89,20 +89,20 @@ class AccountInvoice(models.Model):
|
||||
zero_timesheet_revenue.write({'timesheet_invoice_id': invoice.id})
|
||||
|
||||
# invoicing analytic lines of different currency
|
||||
total_revenue_per_currency = dict.fromkeys(no_zero_timesheet_revenue.mapped('company_currency_id').ids, 0.0)
|
||||
total_revenue_per_currency = dict.fromkeys(no_zero_timesheet_revenue.mapped('currency_id').ids, 0.0)
|
||||
|
||||
for index, timesheet_line in enumerate(no_zero_timesheet_revenue.sorted(key=lambda ts: (ts.date, ts.id))):
|
||||
if index+1 != len(no_zero_timesheet_revenue):
|
||||
price_subtotal_inv = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.company_currency_id)
|
||||
price_subtotal_sol = timesheet_line.so_line.currency_id.compute(timesheet_line.so_line.price_subtotal, timesheet_line.company_currency_id)
|
||||
price_subtotal_inv = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.currency_id)
|
||||
price_subtotal_sol = timesheet_line.so_line.currency_id.compute(timesheet_line.so_line.price_subtotal, timesheet_line.currency_id)
|
||||
line_revenue = timesheet_line.timesheet_revenue * price_subtotal_inv / price_subtotal_sol
|
||||
total_revenue_per_currency[timesheet_line.company_currency_id.id] += line_revenue
|
||||
total_revenue_per_currency[timesheet_line.currency_id.id] += line_revenue
|
||||
else: # last line: add the difference to avoid rounding problem
|
||||
last_price_subtotal_inv = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.company_currency_id)
|
||||
total_revenue = sum([self.env['res.currency'].browse(currency_id).compute(amount, timesheet_line.company_currency_id) for currency_id, amount in total_revenue_per_currency.items()])
|
||||
last_price_subtotal_inv = invoice_line.currency_id.compute(invoice_line.price_subtotal, timesheet_line.currency_id)
|
||||
total_revenue = sum([self.env['res.currency'].browse(currency_id).compute(amount, timesheet_line.currency_id) for currency_id, amount in total_revenue_per_currency.items()])
|
||||
line_revenue = last_price_subtotal_inv - total_revenue
|
||||
|
||||
timesheet_line.write({
|
||||
'timesheet_invoice_id': invoice.id,
|
||||
'timesheet_revenue': timesheet_line.company_currency_id.round(line_revenue),
|
||||
'timesheet_revenue': timesheet_line.currency_id.round(line_revenue),
|
||||
})
|
||||
|
||||
@@ -133,7 +133,7 @@ class TestSaleTimesheet(TestSale):
|
||||
})
|
||||
|
||||
# check we don't compare apples and pears
|
||||
self.assertEquals(timesheet1.company_currency_id, sale_order.currency_id, 'Currencies should not differ (%s vs %s)' % (timesheet1.company_currency_id.name, sale_order.currency_id.name))
|
||||
self.assertEquals(timesheet1.currency_id, sale_order.currency_id, 'Currencies should not differ (%s vs %s)' % (timesheet1.currency_id.name, sale_order.currency_id.name))
|
||||
# check theorical revenue
|
||||
self.assertEquals(timesheet1.timesheet_invoice_type, 'billable_time', "Billable type on task from delivered service should be 'billabe time'")
|
||||
self.assertEquals(timesheet2.timesheet_invoice_type, 'billable_time', "Billable type on task from delivered service should be 'billabe time'")
|
||||
|
||||
Reference in New Issue
Block a user