mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract_price_revision: Improve readability by adding a computed field 'price_can_be_revised'
This commit is contained in:
@@ -20,6 +20,24 @@ class ContractLine(models.Model):
|
||||
string="Variation %",
|
||||
)
|
||||
|
||||
price_can_be_revised = fields.Boolean(
|
||||
compute="_compute_price_can_be_revised",
|
||||
help="Technical field in order to know if the line price can be revised.",
|
||||
)
|
||||
|
||||
@api.depends_context("date_start")
|
||||
def _compute_price_can_be_revised(self):
|
||||
date_start = self.env.context.get("date_start", fields.Datetime.now())
|
||||
lines_can_be_revised = self.filtered(
|
||||
lambda line: not line.automatic_price
|
||||
and not line.successor_contract_line_id
|
||||
and line.recurring_next_date
|
||||
and not line.display_type
|
||||
and (not line.date_end or line.date_end >= date_start)
|
||||
)
|
||||
lines_can_be_revised.price_can_be_revised = True
|
||||
(self - lines_can_be_revised).price_can_be_revised = False
|
||||
|
||||
@api.depends("price_unit", "predecessor_contract_line_id.price_unit")
|
||||
def _compute_variation_percent(self):
|
||||
for line in self:
|
||||
|
||||
@@ -74,10 +74,9 @@ class ContractPriceRevisionWizard(models.TransientModel):
|
||||
|
||||
def _get_contract_lines_to_revise(self, contracts):
|
||||
self.ensure_one()
|
||||
to_revise = contracts.mapped("contract_line_ids").filtered(
|
||||
lambda x: not x.automatic_price
|
||||
and not x.successor_contract_line_id
|
||||
and x.recurring_next_date
|
||||
and (not x.date_end or x.date_end >= self.date_start)
|
||||
to_revise = (
|
||||
contracts.mapped("contract_line_ids")
|
||||
.with_context(date_start=self.date_start)
|
||||
.filtered("price_can_be_revised")
|
||||
)
|
||||
return to_revise
|
||||
|
||||
Reference in New Issue
Block a user