mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX][14.0] tests & typo
This commit is contained in:
@@ -83,15 +83,8 @@ class SaleOrder(models.Model):
|
||||
contract_model = self.env["contract.contract"]
|
||||
contracts = []
|
||||
for rec in self.filtered("is_contract"):
|
||||
line_to_create_contract = rec.order_line.filtered(
|
||||
lambda r: not r.contract_id and r.is_contract
|
||||
)
|
||||
line_to_update_contract = rec.order_line.filtered(
|
||||
lambda r: r.contract_id
|
||||
and r.is_contract
|
||||
and r
|
||||
not in r.contract_id.contract_line_ids.mapped("sale_order_line_id")
|
||||
)
|
||||
line_to_create_contract = rec._get_line_to_create_contract()
|
||||
line_to_update_contract = rec._get_line_to_update_contract()
|
||||
contract_templates = self.env["contract.template"]
|
||||
for order_line in line_to_create_contract:
|
||||
contract_template = order_line.product_id.with_company(
|
||||
|
||||
@@ -141,8 +141,8 @@ class SaleOrderLine(models.Model):
|
||||
rec.date_end = rec._get_date_end() if rec.date_start else False
|
||||
|
||||
@api.onchange("product_id")
|
||||
def onchange_product(self):
|
||||
super().onchange_product()
|
||||
def product_id_change(self):
|
||||
super().product_id_change()
|
||||
for rec in self:
|
||||
if rec.product_id.is_contract:
|
||||
rec.is_contract = True
|
||||
@@ -270,7 +270,7 @@ class SaleOrderLine(models.Model):
|
||||
)
|
||||
|
||||
@api.constrains("product_id", "contract_id")
|
||||
def _check_contract_sale_contract_template(self):
|
||||
def _check_contract_sale_line_is_contract(self):
|
||||
for rec in self:
|
||||
if rec.is_contract and not rec.product_id.is_contract:
|
||||
raise ValidationError(
|
||||
|
||||
@@ -65,8 +65,15 @@ class TestSaleOrder(SavepointCase):
|
||||
cls.order_line1 = cls.sale.order_line.filtered(
|
||||
lambda l: l.product_id == cls.product1
|
||||
)
|
||||
|
||||
cls.order_line1.date_start = "2018-01-01"
|
||||
cls.order_line1.product_uom_qty = 12
|
||||
cls.order_line1.product_id_change()
|
||||
cls.order_line2 = cls.sale.order_line.filtered(
|
||||
lambda l: l.product_id == cls.product2
|
||||
)
|
||||
cls.order_line2.product_id_change()
|
||||
|
||||
pricelist = cls.sale.partner_id.property_product_pricelist.id
|
||||
cls.contract = cls.env["contract.contract"].create(
|
||||
{
|
||||
@@ -194,7 +201,7 @@ class TestSaleOrder(SavepointCase):
|
||||
{
|
||||
"name": "Contract",
|
||||
"contract_template_id": self.contract_template2.id,
|
||||
"partner_id": self.sale.partner_id.id,
|
||||
"partner_id": self.env.user.partner_id.id,
|
||||
"line_recurrence": True,
|
||||
}
|
||||
)
|
||||
@@ -218,6 +225,7 @@ class TestSaleOrder(SavepointCase):
|
||||
def test_no_contract_proudct(self):
|
||||
"""it should create contract for only product contract"""
|
||||
self.product1.is_contract = False
|
||||
self.order_line1.product_id_change()
|
||||
self.sale.action_confirm()
|
||||
self.assertFalse(self.order_line1.contract_id)
|
||||
|
||||
@@ -241,6 +249,7 @@ class TestSaleOrder(SavepointCase):
|
||||
def test_sale_order_create_invoice(self):
|
||||
"""Should not invoice contract product on sale order create invoice"""
|
||||
self.product2.is_contract = False
|
||||
self.order_line2.product_id_change()
|
||||
self.product2.invoice_policy = "order"
|
||||
self.order_line1._compute_auto_renew()
|
||||
self.sale.action_confirm()
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
position="after"
|
||||
>
|
||||
<field name="contract_template_id" attrs="{'invisible': []}" />
|
||||
<field name="is_contract" invisible="1" />
|
||||
<field
|
||||
name="contract_id"
|
||||
options='{"no_create": True}'
|
||||
|
||||
Reference in New Issue
Block a user