mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
@@ -96,9 +96,20 @@ class SaleOrderLine(models.Model):
|
|||||||
return "monthly"
|
return "monthly"
|
||||||
return self.recurring_rule_type
|
return self.recurring_rule_type
|
||||||
|
|
||||||
|
def _get_date_end(self):
|
||||||
|
self.ensure_one()
|
||||||
|
contract_line_model = self.env["contract.line"]
|
||||||
|
date_end = (
|
||||||
|
self.date_start
|
||||||
|
+ contract_line_model.get_relative_delta(
|
||||||
|
self._get_auto_renew_rule_type(), int(self.product_uom_qty),
|
||||||
|
)
|
||||||
|
- relativedelta(days=1)
|
||||||
|
)
|
||||||
|
return date_end
|
||||||
|
|
||||||
@api.onchange('product_id')
|
@api.onchange('product_id')
|
||||||
def onchange_product(self):
|
def onchange_product(self):
|
||||||
contract_line_model = self.env['contract.line']
|
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.product_id.is_contract:
|
if rec.product_id.is_contract:
|
||||||
rec.product_uom_qty = rec.product_id.default_qty
|
rec.product_uom_qty = rec.product_id.default_qty
|
||||||
@@ -108,14 +119,7 @@ class SaleOrderLine(models.Model):
|
|||||||
)
|
)
|
||||||
rec.date_start = rec.date_start or fields.Date.today()
|
rec.date_start = rec.date_start or fields.Date.today()
|
||||||
|
|
||||||
rec.date_end = (
|
rec.date_end = rec._get_date_end()
|
||||||
rec.date_start
|
|
||||||
+ contract_line_model.get_relative_delta(
|
|
||||||
rec._get_auto_renew_rule_type(),
|
|
||||||
int(rec.product_uom_qty),
|
|
||||||
)
|
|
||||||
- relativedelta(days=1)
|
|
||||||
)
|
|
||||||
rec.is_auto_renew = rec.product_id.is_auto_renew
|
rec.is_auto_renew = rec.product_id.is_auto_renew
|
||||||
if rec.is_auto_renew:
|
if rec.is_auto_renew:
|
||||||
rec.auto_renew_interval = (
|
rec.auto_renew_interval = (
|
||||||
@@ -127,19 +131,25 @@ class SaleOrderLine(models.Model):
|
|||||||
|
|
||||||
@api.onchange('date_start', 'product_uom_qty', 'recurring_rule_type')
|
@api.onchange('date_start', 'product_uom_qty', 'recurring_rule_type')
|
||||||
def onchange_date_start(self):
|
def onchange_date_start(self):
|
||||||
contract_line_model = self.env['contract.line']
|
for rec in self.filtered("product_id.is_contract"):
|
||||||
for rec in self.filtered('product_id.is_contract'):
|
rec.date_end = rec._get_date_end() if rec.date_start else False
|
||||||
if not rec.date_start:
|
|
||||||
rec.date_end = False
|
def _get_contract_line_qty(self):
|
||||||
else:
|
"""Returns the quantity to be put on new contract lines."""
|
||||||
rec.date_end = (
|
self.ensure_one()
|
||||||
rec.date_start
|
# The quantity on the generated contract line is 1, as it
|
||||||
+ contract_line_model.get_relative_delta(
|
# correspond to the most common use cases:
|
||||||
rec._get_auto_renew_rule_type(),
|
# - quantity on the SO line = number of periods sold and unit
|
||||||
int(rec.product_uom_qty),
|
# price the price of one period, so the
|
||||||
)
|
# total amount of the SO corresponds to the planned value
|
||||||
- relativedelta(days=1)
|
# of the contract; in this case the quantity on the contract
|
||||||
)
|
# line must be 1
|
||||||
|
# - quantity on the SO line = number of hours sold,
|
||||||
|
# automatic invoicing of the actual hours through a variable
|
||||||
|
# quantity formula, in which case the quantity on the contract
|
||||||
|
# line is not used
|
||||||
|
# Other use cases are easy to implement by overriding this method.
|
||||||
|
return 1.0
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _prepare_contract_line_values(
|
def _prepare_contract_line_values(
|
||||||
@@ -169,19 +179,7 @@ class SaleOrderLine(models.Model):
|
|||||||
'sequence': self.sequence,
|
'sequence': self.sequence,
|
||||||
'product_id': self.product_id.id,
|
'product_id': self.product_id.id,
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
# The quantity on the generated contract line is 1, as it
|
'quantity': self._get_contract_line_qty(),
|
||||||
# correspond to the most common use cases:
|
|
||||||
# - quantity on the SO line = number of periods sold and unit
|
|
||||||
# price the price of one period, so the
|
|
||||||
# total amount of the SO corresponds to the planned value
|
|
||||||
# of the contract; in this case the quantity on the contract
|
|
||||||
# line must be 1
|
|
||||||
# - quantity on the SO line = number of hours sold,
|
|
||||||
# automatic invoicing of the actual hours through a variable
|
|
||||||
# quantity formula, in which case the quantity on the contract
|
|
||||||
# line is not used
|
|
||||||
# Other use cases are easy to implement by overriding this method.
|
|
||||||
'quantity': 1.0,
|
|
||||||
'uom_id': self.product_uom.id,
|
'uom_id': self.product_uom.id,
|
||||||
'price_unit': self.price_unit,
|
'price_unit': self.price_unit,
|
||||||
'discount': self.discount,
|
'discount': self.discount,
|
||||||
|
|||||||
Reference in New Issue
Block a user