diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index 1d212d31bf8..4b10076cd6d 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -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): diff --git a/addons/account/views/account_analytic_view.xml b/addons/account/views/account_analytic_view.xml index 842a7f308ae..ab08b3c15bf 100644 --- a/addons/account/views/account_analytic_view.xml +++ b/addons/account/views/account_analytic_view.xml @@ -14,9 +14,6 @@ - - - diff --git a/addons/sale/models/analytic.py b/addons/sale/models/analytic.py index 7c92065aa05..d8bbb2da419 100644 --- a/addons/sale/models/analytic.py +++ b/addons/sale/models/analytic.py @@ -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 diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 733dad9a0a2..2f7d1021a94 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -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): diff --git a/addons/sale_timesheet/models/account_invoice.py b/addons/sale_timesheet/models/account_invoice.py index c4eb3d46c38..16e73b677ad 100644 --- a/addons/sale_timesheet/models/account_invoice.py +++ b/addons/sale_timesheet/models/account_invoice.py @@ -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), }) diff --git a/addons/sale_timesheet/tests/test_timesheet_revenue.py b/addons/sale_timesheet/tests/test_timesheet_revenue.py index 79c14e68c16..eb33a366bf8 100644 --- a/addons/sale_timesheet/tests/test_timesheet_revenue.py +++ b/addons/sale_timesheet/tests/test_timesheet_revenue.py @@ -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'")