Browse Source

[FIX] - Compute recurring_next_date before create contract line

pull/208/head
sbejaoui 6 years ago
committed by Thomas Binsfeld
parent
commit
c8ec4f3404
  1. 10
      product_contract/models/sale_order_line.py
  2. 20
      product_contract/tests/test_sale_order.py

10
product_contract/models/sale_order_line.py

@ -64,6 +64,7 @@ class SaleOrderLine(models.Model):
@api.multi
def _prepare_contract_line_values(self, contract):
self.ensure_one()
contract_line_env = self.env['account.analytic.invoice.line']
return {
'sequence': self.sequence,
'product_id': self.product_id.id,
@ -74,6 +75,13 @@ class SaleOrderLine(models.Model):
'discount': self.discount,
'date_end': self.date_end,
'date_start': self.date_start or fields.Date.today(),
'recurring_next_date':
contract_line_env._compute_first_recurring_next_date(
self.date_start or fields.Date.today(),
self.recurring_invoicing_type,
self.recurring_rule_type,
self.recurring_interval,
),
'recurring_interval': self.recurring_interval,
'recurring_invoicing_type': self.recurring_invoicing_type,
'recurring_rule_type': self.recurring_rule_type,
@ -89,7 +97,7 @@ class SaleOrderLine(models.Model):
contract_line |= contract_line_env.create(
rec._prepare_contract_line_values(contract)
)
contract_line._onchange_date_start()
return contract_line
@api.constrains('contract_id')
def _check_contract_sale_partner(self):

20
product_contract/tests/test_sale_order.py

@ -16,7 +16,25 @@ class TestSaleOrder(TransactionCase):
{'name': 'Template 1'}
)
self.contract_template2 = self.env['account.analytic.contract'].create(
{'name': 'Template 2'}
{
'name': 'Template 2',
'recurring_invoice_line_ids': [
(
0,
0,
{
'product_id': self.product2.id,
'name': 'Services from #START# to #END#',
'quantity': 1,
'uom_id': self.product2.uom_id.id,
'price_unit': 100,
'discount': 50,
'recurring_rule_type': 'yearly',
'recurring_interval': 1,
},
)
],
}
)
self.product1.write(
{

Loading…
Cancel
Save