mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
fix test import and use uom rouding for float_compare
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from . import test_contract_split
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestContractSplit(TestContractBase):
|
||||
"quantity_to_split": line.quantity,
|
||||
},
|
||||
)
|
||||
for line in self.contract_line_ids
|
||||
for line in self.contract3.contract_line_ids
|
||||
],
|
||||
}
|
||||
self.assertEqual(self.contract3._get_default_split_values(), expected_result)
|
||||
@@ -58,6 +58,7 @@ class TestContractSplit(TestContractBase):
|
||||
.create({})
|
||||
)
|
||||
wizard.partner_id = self.partner_2.id
|
||||
wizard.split_line_ids.quantity_to_split = 0
|
||||
initial_contracts_length = self.env["contract.contract"].search_count([])
|
||||
# confirm wizard without setting to_split quantities
|
||||
wizard.action_split_contract()
|
||||
@@ -75,6 +76,7 @@ class TestContractSplit(TestContractBase):
|
||||
.create({})
|
||||
)
|
||||
wizard.partner_id = self.partner_2.id
|
||||
wizard.split_line_ids.quantity_to_split = 0
|
||||
initial_contracts_length = self.env["contract.contract"].search_count([])
|
||||
# set quantity to split in the wizard
|
||||
wizard.split_line_ids[0].quantity_to_split = wizard.split_line_ids[
|
||||
@@ -87,10 +89,10 @@ class TestContractSplit(TestContractBase):
|
||||
initial_contracts_length + 1, self.env["contract.contract"].search_count([])
|
||||
)
|
||||
# new contract has now the splitted line
|
||||
self.assertEqual(self.partner2.id, new_contract.partner_id.id)
|
||||
self.assertEqual(self.partner_2.id, new_contract.partner_id.id)
|
||||
self.assertEqual(1, len(new_contract.contract_line_ids.ids))
|
||||
self.assertEqual(
|
||||
self.contract3.id,
|
||||
self.contract3,
|
||||
new_contract.contract_line_ids.mapped("splitted_from_contract_id"),
|
||||
)
|
||||
# Original contract has now only 2 lines (3 at the beginning)
|
||||
@@ -107,6 +109,7 @@ class TestContractSplit(TestContractBase):
|
||||
.create({})
|
||||
)
|
||||
wizard.partner_id = self.partner_2.id
|
||||
wizard.split_line_ids.quantity_to_split = 0
|
||||
initial_contracts_length = self.env["contract.contract"].search_count([])
|
||||
# set quantity to split in the wizard
|
||||
wizard.split_line_ids.filtered(lambda l: l.name == "Line").quantity_to_split = 1
|
||||
@@ -116,13 +119,13 @@ class TestContractSplit(TestContractBase):
|
||||
self.assertEqual(
|
||||
initial_contracts_length + 1, self.env["contract.contract"].search_count([])
|
||||
)
|
||||
# new contract has partner2 as partner_id
|
||||
self.assertEqual(self.partner2.id, new_contract.partner_id.id)
|
||||
# new contract has partner_2 as partner_id
|
||||
self.assertEqual(self.partner_2.id, new_contract.partner_id.id)
|
||||
# new contract has now the splitted line with a qty of one
|
||||
self.assertEqual(1, len(new_contract.contract_line_ids.ids))
|
||||
self.assertEqual(1, new_contract.contract_line_ids.quantity)
|
||||
self.assertEqual(
|
||||
self.contract3.id,
|
||||
self.contract3,
|
||||
new_contract.contract_line_ids.mapped("splitted_from_contract_id"),
|
||||
)
|
||||
# Original contract still has 3 lines but with a qty=1 in the last line named "Line"
|
||||
@@ -141,9 +144,7 @@ class TestContractSplit(TestContractBase):
|
||||
.create({})
|
||||
)
|
||||
# set quantity to split in the wizard
|
||||
with self.assertRaises(ValidationError):
|
||||
wizard.split_line_ids[0].quantity_to_split = (
|
||||
wizard.split_line_ids[0].original_qty + 2
|
||||
)
|
||||
# confirm wizard with setting to_split quantities that should raise an error
|
||||
with self.assertRaises(ValidationError):
|
||||
wizard.action_split_contract()
|
||||
|
||||
@@ -44,13 +44,19 @@ class SplitContract(models.TransientModel):
|
||||
contract_obj._get_values_create_split_contract(self)
|
||||
)
|
||||
# TODO: play onchange on partner_id. use onchange_helper from OCA ?
|
||||
precision = self.env["decimal.precision"].precision_get(
|
||||
"Product Unit of Measure"
|
||||
)
|
||||
for line in self.split_line_ids:
|
||||
original_line = line.original_contract_line_id
|
||||
if not line.quantity_to_split:
|
||||
continue
|
||||
if (
|
||||
float_compare(
|
||||
line.quantity_to_split, line.original_qty, precision_digits=2
|
||||
line.quantity_to_split,
|
||||
line.original_qty,
|
||||
precision_digits=line.uom_id and None or precision,
|
||||
precision_rounding=line.uom_id.rounding or None,
|
||||
)
|
||||
== 0
|
||||
):
|
||||
@@ -60,7 +66,10 @@ class SplitContract(models.TransientModel):
|
||||
)
|
||||
elif (
|
||||
float_compare(
|
||||
line.quantity_to_split, line.original_qty, precision_digits=2
|
||||
line.quantity_to_split,
|
||||
line.original_qty,
|
||||
precision_digits=line.uom_id and None or precision,
|
||||
precision_rounding=line.uom_id.rounding or None,
|
||||
)
|
||||
< 0
|
||||
):
|
||||
@@ -108,10 +117,16 @@ class SplitContractLine(models.TransientModel):
|
||||
|
||||
@api.constrains("quantity_to_split")
|
||||
def _check_quantity_to_move(self):
|
||||
precision = self.env["decimal.precision"].precision_get(
|
||||
"Product Unit of Measure"
|
||||
)
|
||||
for rec in self:
|
||||
if (
|
||||
float_compare(
|
||||
rec.quantity_to_split, rec.original_qty, precision_digits=2
|
||||
rec.quantity_to_split,
|
||||
rec.original_qty,
|
||||
precision_digits=rec.uom_id and None or precision,
|
||||
precision_rounding=rec.uom_id.rounding or None,
|
||||
)
|
||||
> 0
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user