mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] contract: Currency is not editable + pricelist from partner
Previous related field was not accurated nor editable. Now the field is got properly from a computed field. Reviewing this, as the currency was taken (and it continues being taken) from the partner pricelist if no pricelist is explicitly set, automatic price should use the same logic for using partner pricelist.
This commit is contained in:
@@ -191,12 +191,18 @@ class ContractAbstractContractLine(models.AbstractModel):
|
||||
"""
|
||||
for line in self:
|
||||
if line.automatic_price:
|
||||
pricelist = (
|
||||
line.contract_id.pricelist_id or
|
||||
line.contract_id.partner_id.with_context(
|
||||
force_company=line.contract_id.company_id.id,
|
||||
).property_product_pricelist
|
||||
)
|
||||
product = line.product_id.with_context(
|
||||
quantity=line.env.context.get(
|
||||
'contract_line_qty',
|
||||
line.quantity,
|
||||
),
|
||||
pricelist=line.contract_id.pricelist_id.id,
|
||||
pricelist=pricelist.id,
|
||||
partner=line.contract_id.partner_id.id,
|
||||
date=line.env.context.get(
|
||||
'old_date', fields.Date.context_today(line)
|
||||
|
||||
@@ -33,7 +33,8 @@ class ContractContract(models.Model):
|
||||
ondelete='restrict',
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
related="company_id.currency_id",
|
||||
compute="_compute_currency_id",
|
||||
comodel_name="res.currency",
|
||||
string="Currency",
|
||||
readonly=True,
|
||||
)
|
||||
@@ -147,6 +148,24 @@ class ContractContract(models.Model):
|
||||
)
|
||||
return invoices
|
||||
|
||||
@api.depends("pricelist_id", "partner_id", "journal_id", "company_id")
|
||||
def _compute_currency_id(self):
|
||||
for rec in self:
|
||||
currency = self.env['res.currency']
|
||||
if any(rec.contract_line_ids.mapped('automatic_price')):
|
||||
# Use pricelist currency
|
||||
currency = (
|
||||
rec.pricelist_id.currency_id or
|
||||
rec.partner_id.with_context(
|
||||
force_company=rec.company_id.id,
|
||||
).property_product_pricelist.currency_id
|
||||
)
|
||||
rec.currency_id = (
|
||||
currency.id or
|
||||
rec.journal_id.currency_id.id or
|
||||
rec.company_id.currency_id.id
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_count(self):
|
||||
for rec in self:
|
||||
@@ -299,11 +318,6 @@ class ContractContract(models.Model):
|
||||
_("Please define a %s journal for the company '%s'.")
|
||||
% (self.contract_type, self.company_id.name or '')
|
||||
)
|
||||
currency = (
|
||||
self.pricelist_id.currency_id
|
||||
or self.partner_id.property_product_pricelist.currency_id
|
||||
or self.company_id.currency_id
|
||||
)
|
||||
invoice_type = 'out_invoice'
|
||||
if self.contract_type == 'purchase':
|
||||
invoice_type = 'in_invoice'
|
||||
@@ -318,7 +332,7 @@ class ContractContract(models.Model):
|
||||
invoice_vals = vinvoice._convert_to_write(vinvoice._cache)
|
||||
invoice_vals.update({
|
||||
'name': self.code,
|
||||
'currency_id': currency.id,
|
||||
'currency_id': self.currency_id.id,
|
||||
'date_invoice': date_invoice,
|
||||
'journal_id': journal.id,
|
||||
'origin': self.name,
|
||||
|
||||
@@ -178,8 +178,6 @@
|
||||
options="{'no_create': True}"
|
||||
groups="base.group_multi_company"/>
|
||||
<field name="currency_id"
|
||||
attrs="{'readonly': [('is_terminated','=',True)]}"
|
||||
options="{'no_create': True}"
|
||||
groups="base.group_multi_currency"/>
|
||||
<field name="invoice_partner_id"
|
||||
attrs="{'readonly': [('is_terminated','=',True)]}"
|
||||
|
||||
Reference in New Issue
Block a user