[FIX][14.0] tests & typo

This commit is contained in:
Mourad
2023-05-04 16:41:52 +02:00
parent 7f00957670
commit fae86d5180
4 changed files with 16 additions and 13 deletions

View File

@@ -83,15 +83,8 @@ class SaleOrder(models.Model):
contract_model = self.env["contract.contract"] contract_model = self.env["contract.contract"]
contracts = [] contracts = []
for rec in self.filtered("is_contract"): for rec in self.filtered("is_contract"):
line_to_create_contract = rec.order_line.filtered( line_to_create_contract = rec._get_line_to_create_contract()
lambda r: not r.contract_id and r.is_contract line_to_update_contract = rec._get_line_to_update_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")
)
contract_templates = self.env["contract.template"] contract_templates = self.env["contract.template"]
for order_line in line_to_create_contract: for order_line in line_to_create_contract:
contract_template = order_line.product_id.with_company( contract_template = order_line.product_id.with_company(

View File

@@ -141,8 +141,8 @@ class SaleOrderLine(models.Model):
rec.date_end = rec._get_date_end() if rec.date_start else False rec.date_end = rec._get_date_end() if rec.date_start else False
@api.onchange("product_id") @api.onchange("product_id")
def onchange_product(self): def product_id_change(self):
super().onchange_product() super().product_id_change()
for rec in self: for rec in self:
if rec.product_id.is_contract: if rec.product_id.is_contract:
rec.is_contract = True rec.is_contract = True
@@ -270,7 +270,7 @@ class SaleOrderLine(models.Model):
) )
@api.constrains("product_id", "contract_id") @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: for rec in self:
if rec.is_contract and not rec.product_id.is_contract: if rec.is_contract and not rec.product_id.is_contract:
raise ValidationError( raise ValidationError(

View File

@@ -65,8 +65,15 @@ class TestSaleOrder(SavepointCase):
cls.order_line1 = cls.sale.order_line.filtered( cls.order_line1 = cls.sale.order_line.filtered(
lambda l: l.product_id == cls.product1 lambda l: l.product_id == cls.product1
) )
cls.order_line1.date_start = "2018-01-01" cls.order_line1.date_start = "2018-01-01"
cls.order_line1.product_uom_qty = 12 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 pricelist = cls.sale.partner_id.property_product_pricelist.id
cls.contract = cls.env["contract.contract"].create( cls.contract = cls.env["contract.contract"].create(
{ {
@@ -194,7 +201,7 @@ class TestSaleOrder(SavepointCase):
{ {
"name": "Contract", "name": "Contract",
"contract_template_id": self.contract_template2.id, "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, "line_recurrence": True,
} }
) )
@@ -218,6 +225,7 @@ class TestSaleOrder(SavepointCase):
def test_no_contract_proudct(self): def test_no_contract_proudct(self):
"""it should create contract for only product contract""" """it should create contract for only product contract"""
self.product1.is_contract = False self.product1.is_contract = False
self.order_line1.product_id_change()
self.sale.action_confirm() self.sale.action_confirm()
self.assertFalse(self.order_line1.contract_id) self.assertFalse(self.order_line1.contract_id)
@@ -241,6 +249,7 @@ class TestSaleOrder(SavepointCase):
def test_sale_order_create_invoice(self): def test_sale_order_create_invoice(self):
"""Should not invoice contract product on sale order create invoice""" """Should not invoice contract product on sale order create invoice"""
self.product2.is_contract = False self.product2.is_contract = False
self.order_line2.product_id_change()
self.product2.invoice_policy = "order" self.product2.invoice_policy = "order"
self.order_line1._compute_auto_renew() self.order_line1._compute_auto_renew()
self.sale.action_confirm() self.sale.action_confirm()

View File

@@ -38,6 +38,7 @@
position="after" position="after"
> >
<field name="contract_template_id" attrs="{'invisible': []}" /> <field name="contract_template_id" attrs="{'invisible': []}" />
<field name="is_contract" invisible="1" />
<field <field
name="contract_id" name="contract_id"
options='{"no_create": True}' options='{"no_create": True}'