[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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user