Browse Source

[IMP] - Upsell/Downsell contract from sale order

pull/208/head
sbejaoui 6 years ago
committed by Thomas Binsfeld
parent
commit
29a83d7769
  1. 6
      product_contract/__manifest__.py
  2. 1
      product_contract/models/product_template.py
  3. 1
      product_contract/models/sale_order.py
  4. 9
      product_contract/models/sale_order_line.py
  5. 1
      product_contract/tests/test_product.py
  6. 43
      product_contract/tests/test_sale_order.py
  7. 17
      product_contract/views/sale_order.xml

6
product_contract/__manifest__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -12,10 +11,7 @@
"ACSONE SA/NV, "
"Odoo Community Association (OCA)",
'website': 'https://github.com/oca/contract',
'depends': [
'product',
'contract_sale',
],
'depends': ['product', 'contract_sale'],
'data': [
'views/product_template.xml',
'views/sale_order.xml',

1
product_contract/models/product_template.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

1
product_contract/models/sale_order.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

9
product_contract/models/sale_order_line.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2017 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -51,6 +50,13 @@ class SaleOrderLine(models.Model):
date_start = fields.Date(string='Date Start')
date_end = fields.Date(string='Date End', index=True)
contract_line_id = fields.Many2one(
comodel_name="account.analytic.invoice.line",
string="Contract Line to replace",
required=False,
copy=False,
)
@api.onchange('product_id')
def onchange_product(self):
if self.product_id.is_contract:
@ -97,6 +103,7 @@ class SaleOrderLine(models.Model):
contract_line |= contract_line_env.create(
rec._prepare_contract_line_values(contract)
)
rec.contract_line_id.stop(rec.date_start)
return contract_line
@api.constrains('contract_id')

1
product_contract/tests/test_product.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

43
product_contract/tests/test_sale_order.py

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from odoo.fields import Date
class TestSaleOrder(TransactionCase):
@ -51,6 +52,36 @@ class TestSaleOrder(TransactionCase):
self.order_line1 = self.sale.order_line.filtered(
lambda l: l.product_id == self.product1
)
self.contract = self.env["account.analytic.account"].create(
{
"name": "Test Contract 2",
"partner_id": self.sale.partner_id.id,
"pricelist_id":
self.sale.partner_id.property_product_pricelist.id,
"recurring_invoices": True,
"contract_type": "purchase",
"contract_template_id": self.contract_template1.id,
"recurring_invoice_line_ids": [
(
0,
0,
{
"product_id": self.product1.id,
"name": "Services from #START# to #END#",
"quantity": 1,
"uom_id": self.product1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "monthly",
"recurring_interval": 1,
"date_start": "2016-02-15",
"recurring_next_date": "2016-02-29",
},
)
],
}
)
self.contract_line = self.contract.recurring_invoice_line_ids[0]
def test_compute_is_contract(self):
"""Sale Order should have is_contract true if one of its lines is
@ -153,3 +184,13 @@ class TestSaleOrder(TransactionCase):
self.sale.action_confirm()
invoice = self.order_line1.contract_id.recurring_create_invoice()
self.assertTrue(invoice in self.sale.invoice_ids)
def test_contract_upsell(self):
"""Should stop contract line at sale order line start date"""
self.order_line1.contract_id = self.contract
self.order_line1.contract_line_id = self.contract_line
self.order_line1.date_start = "2018-01-01"
self.sale.action_confirm()
self.assertEqual(
self.contract_line.date_end, Date.to_date("2018-01-01")
)

17
product_contract/views/sale_order.xml

@ -25,14 +25,17 @@
<xpath expr="//field[@name='order_line']" position="before">
<field name="is_contract" invisible="1"/>
</xpath>
<xpath expr="//field[@name='order_line']/form//field[@name='product_id']"
<xpath expr="//field[@name='order_line']/form//field[@name='product_id']"
position="after">
<field name="contract_template_id" invisible="1"/>
<field name="contract_id"
attrs="{'invisible': [('is_contract', '=', False)]}"
domain="[('partner_id','=',parent.partner_id),('contract_template_id','=',contract_template_id)]"
/>
</xpath>
<field name="contract_template_id" invisible="1"/>
<field name="contract_id"
attrs="{'invisible': [('is_contract', '=', False)]}"
domain="[('partner_id','=',parent.partner_id),('contract_template_id','=',contract_template_id)]"/>
<field name="contract_line_id"
attrs="{'invisible': [('is_contract', '=', False)]}"
domain="[('contract_id','=',contract_id)]"/>
</xpath>
<xpath expr="//field[@name='order_line']/form//field[@name='tax_id']/parent::group"
position="after">
<separator colspan="4" string="Recurrence Invoicing"

Loading…
Cancel
Save