Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][FIX] product_contract: Compute date_start from the current date instead of date_order #1191

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions product_contract/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,29 @@ def _compute_contract_template_id(self):

@api.depends("product_id")
def _compute_date_start(self):
today = fields.Date.context_today(self)
for sol in self:
if sol.contract_start_date_method == "start_this":
sol.date_start = sol.order_id.date_order.replace(day=1)
sol.date_start = today.replace(day=1)
elif sol.contract_start_date_method == "end_this":
sol.date_start = (
sol.order_id.date_order
today
+ self.get_relative_delta(
sol.recurring_rule_type, sol.product_id.default_qty
)
).replace(day=1) - relativedelta(days=1)
elif sol.contract_start_date_method == "start_next":
# Dia 1 del siguiente recurring_rule_type
sol.date_start = (
sol.order_id.date_order
today
+ self.get_relative_delta(
sol.recurring_rule_type, sol.product_id.default_qty
)
).replace(day=1)
elif sol.contract_start_date_method == "end_next":
# Last day of next recurring period
sol.date_start = (
sol.order_id.date_order
today
+ self.get_relative_delta(
sol.recurring_rule_type, sol.product_id.default_qty + 1
)
Expand Down Expand Up @@ -190,7 +191,7 @@ def _prepare_contract_line_values(
recurring_next_date = self.env[
"contract.line"
]._compute_first_recurring_next_date(
self.date_start or fields.Date.today(),
self.date_start or fields.Date.context_today(self),
self.recurring_invoicing_type,
self.recurring_rule_type,
1,
Expand All @@ -206,7 +207,7 @@ def _prepare_contract_line_values(
"price_unit": self.price_unit,
"discount": self.discount,
"date_end": self.date_end,
"date_start": self.date_start or fields.Date.today(),
"date_start": self.date_start or fields.Date.context_today(self),
"recurring_next_date": recurring_next_date,
"recurring_interval": self.recurring_interval or 1,
"recurring_invoicing_type": self.recurring_invoicing_type,
Expand Down Expand Up @@ -308,7 +309,7 @@ def _set_contract_line_start_date(self):
):
continue
is_end = "end_" in line.contract_start_date_method
today = fields.Date.today()
today = fields.Date.context_today(self)
month_period = month = today.month
month_nb = MONTH_NB_MAPPING[line.recurring_rule_type]
# The period number is started by 0 to be able to calculate the month
Expand Down