[FIX] project_account, project_purchase, sale_project: default currency
In the multi-company context, it is possible to create an analytic account without a defined company. The result is that the analytic account will not have a currency. A traceback will be triggered when calculating the profitability of a project (for example by changing its status when the 'sale_timesheet' module is installed). Solution: Use the currency of the project. Introduced by: 68b4ea69c173dd5894bcb42b99e6818f241f9734 opw-3292417 closes odoo/odoo#121143 X-original-commit: 90512da68f776459a8a65bed285f5a178f9dd77d Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com> Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
This commit is contained in:
@@ -31,14 +31,14 @@ class Project(models.Model):
|
||||
self._cr.execute(query_string, query_param)
|
||||
bills_move_line_read = self._cr.dictfetchall()
|
||||
if bills_move_line_read:
|
||||
# Get conversion rate from currencies to currency of analytic account
|
||||
currency_ids = {bml['currency_id'] for bml in bills_move_line_read + [{'currency_id': self.analytic_account_id.currency_id.id}]}
|
||||
# Get conversion rate from currencies to currency of the project
|
||||
currency_ids = {bml['currency_id'] for bml in bills_move_line_read + [{'currency_id': self.currency_id.id}]}
|
||||
rates = self.env['res.currency'].browse(list(currency_ids))._get_rates(self.company_id, date.today())
|
||||
conversion_rates = {cid: rates[self.analytic_account_id.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
conversion_rates = {cid: rates[self.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
move_ids = set()
|
||||
for moves_read in bills_move_line_read:
|
||||
price_subtotal = self.analytic_account_id.currency_id.round(moves_read['price_subtotal'] * conversion_rates[moves_read['currency_id']])
|
||||
price_subtotal = self.currency_id.round(moves_read['price_subtotal'] * conversion_rates[moves_read['currency_id']])
|
||||
analytic_contribution = moves_read['analytic_distribution'][str(self.analytic_account_id.id)] / 100.
|
||||
move_ids.add(moves_read['move_id'])
|
||||
if moves_read['parent_state'] == 'draft':
|
||||
|
||||
@@ -139,16 +139,16 @@ class Project(models.Model):
|
||||
with_action = with_action and self.user_has_groups('purchase.group_purchase_user, account.group_account_invoice, account.group_account_readonly')
|
||||
if purchase_order_line_read:
|
||||
|
||||
# Get conversion rate from currencies to currency of analytic account
|
||||
currency_ids = {pol['currency_id'] for pol in purchase_order_line_read + [{'currency_id': self.analytic_account_id.currency_id.id}]}
|
||||
# Get conversion rate from currencies to currency of the project
|
||||
currency_ids = {pol['currency_id'] for pol in purchase_order_line_read + [{'currency_id': self.currency_id.id}]}
|
||||
rates = self.env['res.currency'].browse(list(currency_ids))._get_rates(self.company_id, date.today())
|
||||
conversion_rates = {cid: rates[self.analytic_account_id.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
conversion_rates = {cid: rates[self.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
purchase_order_line_ids = []
|
||||
for pol_read in purchase_order_line_read:
|
||||
purchase_order_line_invoice_line_ids.extend(pol_read['invoice_lines'].ids)
|
||||
price_unit = self.analytic_account_id.currency_id.round(pol_read['price_unit'] * conversion_rates[pol_read['currency_id']])
|
||||
price_unit = self.currency_id.round(pol_read['price_unit'] * conversion_rates[pol_read['currency_id']])
|
||||
analytic_contribution = pol_read['analytic_distribution'][str(self.analytic_account_id.id)] / 100.
|
||||
amount_invoiced -= price_unit * pol_read['qty_invoiced'] * analytic_contribution if pol_read['qty_invoiced'] > 0 else 0.0
|
||||
if pol_read['qty_to_invoice'] > 0:
|
||||
|
||||
@@ -468,15 +468,15 @@ class Project(models.Model):
|
||||
invoices_move_line_read = self._cr.dictfetchall()
|
||||
if invoices_move_line_read:
|
||||
|
||||
# Get conversion rate from currencies to currency of analytic account
|
||||
currency_ids = {iml['currency_id'] for iml in invoices_move_line_read + [{'currency_id': self.analytic_account_id.currency_id.id}]}
|
||||
# Get conversion rate from currencies to currency of the project
|
||||
currency_ids = {iml['currency_id'] for iml in invoices_move_line_read + [{'currency_id': self.currency_id.id}]}
|
||||
rates = self.env['res.currency'].browse(list(currency_ids))._get_rates(self.company_id, date.today())
|
||||
conversion_rates = {cid: rates[self.analytic_account_id.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
conversion_rates = {cid: rates[self.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
|
||||
move_ids = set()
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
for moves_read in invoices_move_line_read:
|
||||
price_subtotal = self.analytic_account_id.currency_id.round(moves_read['price_subtotal'] * conversion_rates[moves_read['currency_id']])
|
||||
price_subtotal = self.currency_id.round(moves_read['price_subtotal'] * conversion_rates[moves_read['currency_id']])
|
||||
analytic_contribution = moves_read['analytic_distribution'][str(self.analytic_account_id.id)] / 100.
|
||||
move_ids.add(moves_read['move_id'])
|
||||
if moves_read['parent_state'] == 'draft':
|
||||
|
||||
Reference in New Issue
Block a user