summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ledoux <dle@odoo.com>2016-01-04 14:40:53 +0100
committerDenis Ledoux <dle@odoo.com>2016-01-04 14:53:16 +0100
commit52db42d3dfd7c0942d96fd9dfe4f80fd7eddedcf (patch)
tree0337c9f18c1544b59e281114c9ea33c42613924c
parent2f562af355788ea8175e09de371331372eb0f5c5 (diff)
[FIX] account: multi-company payment term
Despite the fact there is a `company_id` field on `account.payment.term`, there is no multi-company record rule on this model. The payment terms are therefore shared by default accross companies, even if the company is filled on the payment term. In addition: - The `company_id` field on `account.payment.term` is required - The field is invisible on the payment term form - The default value is the user company Adding the record rule would imply to change: - The fact the `company_id` field is required, as you probably would like to share some payment terms accross companies, by leaving empty this field on the payment term form - The field should be visible in the form for users having the multi-company group, so the admins can create payment terms for other companies than the one they are currently in. This cannot be done in a stable release, such as 9.0. This is for master. In the mean time, we keep the behavior as it was in 8.0: We consider that the payment terms are shared among companies, and the `company_id` field is simply ignored. This implies that choosing a payment term from another company in an invoice must not lead to multi-company access rights issues, as it was the case before this revision: If a user other than the admin chose a payment term from another company, the on change on the payment term leaded to access rights issues, as it needed the read access on the company of the payment term, to get the currency decimal places. From this revision, the currency is took from the invoice directly, through the context, and if not passed in the context, the company of the user is used instead of the company of the paymen term. It makes more sense anyway to take the currency from the invoice instead of the currency of the payment term company to retrieve the currency decimal places. opw-659818
-rw-r--r--addons/account/models/account_invoice.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index e39a8c78f2e..8e42d0ec181 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -487,7 +487,7 @@ class AccountInvoice(models.Model):
self.date_due = self.date_due or self.date_invoice
else:
pterm = self.payment_term_id
- pterm_list = pterm.compute(value=1, date_ref=date_invoice)[0]
+ pterm_list = pterm.with_context(currency_id=self.currency_id.id).compute(value=1, date_ref=date_invoice)[0]
self.date_due = max(line[0] for line in pterm_list)
@api.multi
@@ -691,7 +691,7 @@ class AccountInvoice(models.Model):
name = inv.name or '/'
if inv.payment_term_id:
- totlines = inv.with_context(ctx).payment_term_id.compute(total, date_invoice)[0]
+ totlines = inv.with_context(ctx).payment_term_id.with_context(currency_id=inv.currency_id.id).compute(total, date_invoice)[0]
res_amount_currency = total_currency
ctx['date'] = date_invoice
for i, t in enumerate(totlines):
@@ -1227,7 +1227,11 @@ class AccountPaymentTerm(models.Model):
date_ref = date_ref or fields.Date.today()
amount = value
result = []
- prec = self.company_id.currency_id.decimal_places
+ if self.env.context.get('currency_id'):
+ currency = self.env['res.currency'].browse(self.env.context['currency_id'])
+ else:
+ currency = self.env.user.company_id.currency_id
+ prec = currency.decimal_places
for line in self.line_ids:
if line.value == 'fixed':
amt = round(line.value_amount, prec)