changeset 6b10943ccf7c in modules/stock_lot_unit:default
details:
https://hg.tryton.org/modules/stock_lot_unit?cmd=changeset;node=6b10943ccf7c
description:
Add wizard to add lots and sequence for lot number
issue9800
review326511002
diffstat:
__init__.py | 5 +-
stock.py | 53 ++++++++++++++++-----
stock.xml | 6 ++
tests/scenario_stock_lot_unit_move_add.rst | 72 ++++++++++++++++++++++++++++++
tests/test_stock_lot_unit.py | 4 +
5 files changed, 126 insertions(+), 14 deletions(-)
diffs (212 lines):
diff -r d2da87f23711 -r 6b10943ccf7c __init__.py
--- a/__init__.py Sat Dec 19 17:08:47 2020 +0100
+++ b/__init__.py Wed Feb 03 21:19:06 2021 +0100
@@ -5,7 +5,9 @@
from . import product
from . import stock
-__all__ = ['register']
+from .stock import LotUnitMixin
+
+__all__ = ['LotUnitMixin', 'register']
def register():
@@ -13,6 +15,7 @@
product.Template,
product.Product,
stock.Lot,
+ stock.MoveAddLotsStartLot,
stock.Move,
stock.Inventory,
stock.ShipmentIn,
diff -r d2da87f23711 -r 6b10943ccf7c stock.py
--- a/stock.py Sat Dec 19 17:08:47 2020 +0100
+++ b/stock.py Wed Feb 03 21:19:06 2021 +0100
@@ -10,8 +10,7 @@
from .exceptions import LotUnitQuantityError
-class Lot(metaclass=PoolMeta):
- __name__ = 'stock.lot'
+class LotUnitMixin:
unit = fields.Many2One(
'product.uom', "Unit",
@@ -21,7 +20,7 @@
depends=['product_default_uom_category'],
help="The biggest unit for the lot.")
unit_quantity = fields.Float(
- "Quantity", digits=(16, Eval('unit_digits', 2)),
+ "Unit Quantity", digits=(16, Eval('unit_digits', 2)),
states={
'required': Bool(Eval('unit')),
'invisible': ~Eval('unit'),
@@ -36,19 +35,10 @@
unit_digits = fields.Function(
fields.Integer("Unit Digits"), 'on_change_with_unit_digits')
- @classmethod
- def __setup__(cls):
- super(Lot, cls).__setup__()
- cls._modify_no_move += [
- ('unit', 'done', 'stock_lot_unit.msg_change_unit'),
- ('unit_quantity', 'done',
- 'stock_lot_unit.msg_change_unit_quantity'),
- ]
-
@fields.depends('product', methods=['on_change_unit'])
def on_change_product(self):
try:
- super(Lot, self).on_change_product()
+ super().on_change_product()
except AttributeError:
pass
if self.product and self.product.lot_unit:
@@ -72,6 +62,43 @@
return self.unit.digits
+class Lot(LotUnitMixin, metaclass=PoolMeta):
+ __name__ = 'stock.lot'
+
+ @classmethod
+ def __setup__(cls):
+ super(Lot, cls).__setup__()
+ cls._modify_no_move += [
+ ('unit', 'done', 'stock_lot_unit.msg_change_unit'),
+ ('unit_quantity', 'done',
+ 'stock_lot_unit.msg_change_unit_quantity'),
+ ]
+
+
+class MoveAddLotsStartLot(LotUnitMixin, metaclass=PoolMeta):
+ __name__ = 'stock.move.add.lots.start.lot'
+
+ @fields.depends(
+ 'unit', 'unit_quantity', 'quantity', 'parent', '_parent_parent.unit')
+ def _set_lot_values(self, lot):
+ pool = Pool()
+ Uom = pool.get('product.uom')
+ super()._set_lot_values(lot)
+ self.unit = lot.unit
+ self.unit_quantity = lot.unit_quantity
+ if self.parent.unit:
+ maximum_quantity = Uom.compute_qty(
+ lot.unit, lot.unit_quantity, self.parent.unit, round=False)
+ if self.quantity > maximum_quantity:
+ self.quantity = self.parent.unit.round(maximum_quantity)
+
+ def _get_lot_values(self, move):
+ values = super()._get_lot_values(move)
+ values['unit'] = self.unit
+ values['unit_quantity'] = self.unit_quantity
+ return values
+
+
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
diff -r d2da87f23711 -r 6b10943ccf7c stock.xml
--- a/stock.xml Sat Dec 19 17:08:47 2020 +0100
+++ b/stock.xml Wed Feb 03 21:19:06 2021 +0100
@@ -14,5 +14,11 @@
<field name="inherit" ref="stock_lot.lot_view_tree"/>
<field name="name">lot_list</field>
</record>
+
+ <record model="ir.ui.view" id="move_add_lots_start_lot_view_list">
+ <field name="model">stock.move.add.lots.start.lot</field>
+ <field name="inherit"
ref="stock_lot.move_add_lots_start_lot_view_list"/>
+ <field name="name">lot_list</field>
+ </record>
</data>
</tryton>
diff -r d2da87f23711 -r 6b10943ccf7c tests/scenario_stock_lot_unit_move_add.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_stock_lot_unit_move_add.rst Wed Feb 03 21:19:06
2021 +0100
@@ -0,0 +1,72 @@
+================================
+Stock Lot Unit Move Add Scenario
+================================
+
+Imports::
+
+ >>> from decimal import Decimal
+ >>> from proteus import Model, Wizard
+ >>> from trytond.tests.tools import activate_modules
+ >>> from trytond.modules.company.tests.tools import create_company
+
+Activate modules::
+
+ >>> config = activate_modules('stock_lot_unit')
+
+Create company::
+
+ >>> _ = create_company()
+
+Create product::
+
+ >>> ProductUom = Model.get('product.uom')
+ >>> ProductTemplate = Model.get('product.template')
+ >>> unit, = ProductUom.find([('name', '=', 'Unit')])
+
+ >>> template = ProductTemplate()
+ >>> template.name = 'Product'
+ >>> template.default_uom = unit
+ >>> template.type = 'goods'
+ >>> template.list_price = Decimal('20')
+ >>> template.save()
+ >>> product, = template.products
+
+Get stock locations::
+
+ >>> Location = Model.get('stock.location')
+ >>> storage_loc, = Location.find([('code', '=', 'STO')])
+ >>> customer_loc, = Location.find([('code', '=', 'CUS')])
+
+Create a move::
+
+ >>> Move = Model.get('stock.move')
+ >>> move = Move()
+ >>> move.from_location = storage_loc
+ >>> move.to_location = customer_loc
+ >>> move.product = product
+ >>> move.quantity = 5
+ >>> move.unit_price = Decimal('20')
+ >>> move.save()
+
+Create a lot::
+
+ >>> Lot = Model.get('stock.lot')
+ >>> lot = Lot(number='01', product=product)
+ >>> lot.unit = unit
+ >>> lot.unit_quantity = 1
+ >>> lot.save()
+
+Add a lot::
+
+ >>> add_lots = Wizard('stock.move.add.lots', [move])
+ >>> lot = add_lots.form.lots.new()
+ >>> lot.quantity
+ 5.0
+ >>> lot.product = product # proteus does not set reverse domain
+ >>> lot.number = '01'
+ >>> lot.unit == unit
+ True
+ >>> lot.unit_quantity
+ 1.0
+ >>> lot.quantity
+ 1.0
diff -r d2da87f23711 -r 6b10943ccf7c tests/test_stock_lot_unit.py
--- a/tests/test_stock_lot_unit.py Sat Dec 19 17:08:47 2020 +0100
+++ b/tests/test_stock_lot_unit.py Wed Feb 03 21:19:06 2021 +0100
@@ -22,4 +22,8 @@
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+ suite.addTests(doctest.DocFileSuite('scenario_stock_lot_unit_move_add.rst',
+ tearDown=doctest_teardown, encoding='utf-8',
+ checker=doctest_checker,
+ optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite