mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] contract_price_revision: Skip revising lines that are not valid anymore
cherry-pick db5c3d6472
This commit is contained in:
@@ -25,12 +25,9 @@ class ContractPriceRevisionWizard(models.TransientModel):
|
||||
|
||||
def action_apply(self):
|
||||
ContractLine = self.env['contract.line']
|
||||
active_ids = self.env.context['active_ids']
|
||||
for line in self.env['contract.contract'].browse(active_ids).mapped(
|
||||
'contract_line_ids'):
|
||||
if (line.automatic_price or line.successor_contract_line_id or
|
||||
not line.recurring_next_date):
|
||||
continue
|
||||
active_ids = self.env.context.get('active_ids')
|
||||
contracts = self.env['contract.contract'].browse(active_ids)
|
||||
for line in self._get_contract_lines_to_revise(contracts):
|
||||
line.update({
|
||||
'date_end': self.date_start - relativedelta(days=1),
|
||||
})
|
||||
@@ -52,3 +49,16 @@ class ContractPriceRevisionWizard(models.TransientModel):
|
||||
'contract', 'action_customer_contract')
|
||||
action['domain'] = [('id', 'in', active_ids)]
|
||||
return action
|
||||
|
||||
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)
|
||||
)
|
||||
)
|
||||
return to_revise
|
||||
|
||||
Reference in New Issue
Block a user