From 39de08712ea34fb7b12cbfb5f90157dfcf5f2982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Aug 2025 11:34:54 +0200 Subject: [PATCH] Add test scenario to request production with BoM --- .../scenario_stock_supply_production_bom.rst | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 modules/stock_supply_production/tests/scenario_stock_supply_production_bom.rst diff --git a/modules/stock_supply_production/tests/scenario_stock_supply_production_bom.rst b/modules/stock_supply_production/tests/scenario_stock_supply_production_bom.rst new file mode 100644 index 0000000000..fd355afa34 --- /dev/null +++ b/modules/stock_supply_production/tests/scenario_stock_supply_production_bom.rst @@ -0,0 +1,76 @@ +==================================== +Production Request with BoM Scenario +==================================== + +Imports:: + + >>> from proteus import Model, Wizard + >>> from trytond.modules.company.tests.tools import create_company + >>> from trytond.tests.tools import activate_modules, assertEqual + + +Activate modules:: + + >>> config = activate_modules('stock_supply_production', create_company) + + >>> BoM = Model.get('production.bom') + >>> Location = Model.get('stock.location') + >>> Move = Model.get('stock.move') + >>> ProductTemplate = Model.get('product.template') + >>> ProductUom = Model.get('product.uom') + >>> Production = Model.get('production') + +Create product with a BoM:: + + >>> unit, = ProductUom.find([('name', '=', 'Unit')]) + >>> box = ProductUom(name="Box", symbol="b", category=unit.category) + >>> box.factor = 10 + >>> box.rounding = 1 + >>> box.digits = 0 + >>> box.save() + + >>> template = ProductTemplate() + >>> template.name = "product" + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.producible = True + >>> template.save() + >>> product, = template.products + + >>> bom = BoM(name="Product") + >>> output = bom.outputs.new() + >>> output.product = product + >>> output.quantity = 1 + >>> output.unit = box + >>> bom.save() + + >>> _ = product.boms.new(bom=bom) + >>> product.save() + +Get stock locations:: + + >>> warehouse_loc, = Location.find([('code', '=', 'WH')]) + >>> storage_loc, = Location.find([('code', '=', 'STO')]) + >>> lost_loc, = Location.find([('type', '=', 'lost_found')]) + +Create needs for product:: + + >>> move = Move() + >>> move.product = product + >>> move.quantity = 2 + >>> move.from_location = storage_loc + >>> move.to_location = lost_loc + >>> move.click('do') + >>> move.state + 'done' + +Create production request:: + + >>> create_pr = Wizard('stock.supply') + >>> create_pr.execute('create_') + + >>> production, = Production.find([]) + >>> assertEqual(production.product, product) + >>> production.quantity + 1.0 + >>> assertEqual(production.unit, box)