mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_secondary_unit: Compatibility with product variants
TT40323
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from . import product
|
||||
# Keep order
|
||||
from . import stock_product_secondary_unit_mixin
|
||||
from . import product_product
|
||||
from . import product_template
|
||||
from . import stock_move
|
||||
|
||||
17
stock_secondary_unit/models/product_product.py
Normal file
17
stock_secondary_unit/models/product_product.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Copyright 2018 Tecnativa - Sergio Teruel
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = ["product.product", "stock.product.secondary.unit.mixin"]
|
||||
_name = "product.product"
|
||||
|
||||
stock_secondary_uom_id = fields.Many2one(
|
||||
comodel_name="product.secondary.unit",
|
||||
string="Second unit for inventory",
|
||||
readonly=False,
|
||||
domain="['|', ('product_id', '=', id),"
|
||||
"'&', ('product_tmpl_id', '=', product_tmpl_id),"
|
||||
" ('product_id', '=', False)]",
|
||||
)
|
||||
14
stock_secondary_unit/models/product_template.py
Normal file
14
stock_secondary_unit/models/product_template.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2018 Tecnativa - Sergio Teruel
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = ["product.template", "stock.product.secondary.unit.mixin"]
|
||||
_name = "product.template"
|
||||
|
||||
stock_secondary_uom_id = fields.Many2one(
|
||||
comodel_name="product.secondary.unit",
|
||||
domain="[('product_tmpl_id', '=', id), ('product_id', '=', False)]",
|
||||
string="Second unit for inventory",
|
||||
)
|
||||
@@ -4,9 +4,9 @@ from odoo import api, fields, models
|
||||
from odoo.tools.float_utils import float_round
|
||||
|
||||
|
||||
class StockProductSecondaryUnit(models.AbstractModel):
|
||||
_name = "stock.product.secondary.unit"
|
||||
_description = "Stock Product Secondary Unit"
|
||||
class StockProductSecondaryUnitMixin(models.AbstractModel):
|
||||
_name = "stock.product.secondary.unit.mixin"
|
||||
_description = "Stock Product Secondary Unit Mixin"
|
||||
|
||||
secondary_unit_qty_available = fields.Float(
|
||||
string="Quantity On Hand (2Unit)",
|
||||
@@ -26,23 +26,3 @@ class StockProductSecondaryUnit(models.AbstractModel):
|
||||
product.secondary_unit_qty_available = float_round(
|
||||
qty, precision_rounding=product.uom_id.rounding
|
||||
)
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = ["product.template", "stock.product.secondary.unit"]
|
||||
_name = "product.template"
|
||||
|
||||
stock_secondary_uom_id = fields.Many2one(
|
||||
comodel_name="product.secondary.unit", string="Second unit for inventory"
|
||||
)
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = ["product.product", "stock.product.secondary.unit"]
|
||||
_name = "product.product"
|
||||
|
||||
stock_secondary_uom_id = fields.Many2one(
|
||||
comodel_name="product.secondary.unit",
|
||||
string="Second unit for inventory",
|
||||
related="product_tmpl_id.stock_secondary_uom_id",
|
||||
)
|
||||
@@ -128,7 +128,7 @@ class TestProductSecondaryUnit(TransactionCase):
|
||||
move_vals = {
|
||||
"product_id": product1.id,
|
||||
"name": product1.display_name,
|
||||
"secondary_uom_id": product1.secondary_uom_ids[0].id,
|
||||
"secondary_uom_id": product1.product_tmpl_id.secondary_uom_ids[0].id,
|
||||
"product_uom": product1.uom_id.id,
|
||||
"product_uom_qty": 10.0,
|
||||
"location_id": self.location_supplier.id,
|
||||
@@ -167,17 +167,17 @@ class TestProductSecondaryUnit(TransactionCase):
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[0]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
|
||||
self.assertEqual(move.product_uom_qty, 0.5)
|
||||
move.secondary_uom_qty = 2
|
||||
self.assertEqual(move.product_uom_qty, 1)
|
||||
move.secondary_uom_id = product.secondary_uom_ids[1]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[1]
|
||||
self.assertEqual(move.product_uom_qty, 1.8)
|
||||
move.product_uom_qty = 5
|
||||
self.assertAlmostEqual(move.secondary_uom_qty, 5.56, 2)
|
||||
# Change uom from stock move line
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[2]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[2]
|
||||
self.assertEqual(move.product_uom_qty, 10)
|
||||
move.product_uom = self.product_uom_ton
|
||||
self.assertAlmostEqual(move.secondary_uom_qty, 1000, 2)
|
||||
@@ -189,11 +189,11 @@ class TestProductSecondaryUnit(TransactionCase):
|
||||
with picking_form.move_line_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[0]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
|
||||
self.assertEqual(move.qty_done, 0.5)
|
||||
move.secondary_uom_qty = 2
|
||||
self.assertEqual(move.qty_done, 1)
|
||||
move.secondary_uom_id = product.secondary_uom_ids[1]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[1]
|
||||
self.assertEqual(move.qty_done, 1.8)
|
||||
move.qty_done = 5
|
||||
self.assertAlmostEqual(move.secondary_uom_qty, 5.56, 2)
|
||||
@@ -209,11 +209,11 @@ class TestProductSecondaryUnit(TransactionCase):
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[0]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[1]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[1]
|
||||
picking = picking_form.save()
|
||||
picking.action_confirm()
|
||||
self.assertEqual(len(picking.move_lines), 2)
|
||||
@@ -229,11 +229,11 @@ class TestProductSecondaryUnit(TransactionCase):
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[0]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = product
|
||||
move.secondary_uom_qty = 1
|
||||
move.secondary_uom_id = product.secondary_uom_ids[0]
|
||||
move.secondary_uom_id = product.product_tmpl_id.secondary_uom_ids[0]
|
||||
picking = picking_form.save()
|
||||
picking.action_confirm()
|
||||
self.assertEqual(len(picking.move_lines), 1)
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
<group string="Secondary unit">
|
||||
<field
|
||||
name="stock_secondary_uom_id"
|
||||
domain="[('product_tmpl_id', '=', id)]"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
</group>
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<field name="secondary_uom_qty" />
|
||||
<field
|
||||
name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
domain="['|', ('product_id', '=', product_id),
|
||||
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
|
||||
('product_id', '=', False)]"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
</field>
|
||||
@@ -31,7 +33,9 @@
|
||||
<field name="secondary_uom_qty" />
|
||||
<field
|
||||
name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
domain="['|', ('product_id', '=', product_id),
|
||||
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
|
||||
('product_id', '=', False)]"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
</field>
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
/>
|
||||
<field
|
||||
name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
domain="['|', ('product_id', '=', product_id),
|
||||
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
|
||||
('product_id', '=', False)]"
|
||||
options="{'no_create': True}"
|
||||
attrs="{'column_invisible': [('parent.immediate_transfer', '=', True)], 'readonly': ['|', ('is_initial_demand_editable', '=', False), '&', '&', ('show_operations', '=', True), ('is_locked', '=', True), ('is_initial_demand_editable', '=', False)]}"
|
||||
/>
|
||||
@@ -33,7 +35,9 @@
|
||||
/>
|
||||
<field
|
||||
name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
domain="['|', ('product_id', '=', product_id),
|
||||
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
|
||||
('product_id', '=', False)]"
|
||||
options="{'no_create': True}"
|
||||
attrs="{'invisible': [('parent.immediate_transfer', '=', True)], 'readonly': [('is_initial_demand_editable', '=', False)]}"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user