Set routing on production request supplied on sale

Closes #13295
This commit is contained in:
Sergi Almacellas Abellana
2024-09-07 11:27:39 +02:00
parent 1fcd308aa6
commit 074c173753
4 changed files with 104 additions and 1 deletions
@@ -20,3 +20,7 @@ def register():
module='sale_supply_production', type_='wizard')
Pool.register(
module='sale_supply_production', type_='report')
Pool.register(
sale.Line_Routing,
module='sale_supply_production', type_='model',
depends=['production_routing'])
+12
View File
@@ -112,3 +112,15 @@ class Line(metaclass=PoolMeta):
state='request',
origin=self,
)
class Line_Routing(metaclass=PoolMeta):
__name__ = 'sale.line'
def get_production(self, product_quantities, bom_pattern=None):
production = super().get_production(
product_quantities, bom_pattern=bom_pattern)
if production and production.product:
if pbom := production.product.get_bom(bom_pattern):
production.routing = pbom.routing
return production
+4 -1
View File
@@ -50,7 +50,10 @@ for dep in info.get('depends', []):
requires.append(get_require_version('trytond_%s' % dep))
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('proteus')]
tests_require = [
get_require_version('proteus'),
get_require_version('trytond_production_routing'),
]
setup(name=name,
version=version,
@@ -0,0 +1,84 @@
=======================================
Sale Supply Production Routing Scenario
=======================================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules(['sale_supply_production', 'production_routing'])
>>> BoM = Model.get('production.bom')
>>> Party = Model.get('party.party')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUom = Model.get('product.uom')
>>> Production = Model.get('production')
>>> Routing = Model.get('production.routing')
>>> Sale = Model.get('sale.sale')
Create company::
>>> _ = create_company()
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name="Customer")
>>> customer.save()
Create product::
>>> unit, = ProductUom.find([('name', '=', "Unit")])
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.producible = True
>>> template.salable = True
>>> template.supply_on_sale = 'always'
>>> template.list_price = Decimal(30)
>>> product, = template.products
>>> product.cost_price = Decimal(20)
>>> template.save()
>>> product, = template.products
Create a Bill of Material with routing::
>>> bom = BoM(name="product")
>>> _ = bom.outputs.new(product=product, quantity=1)
>>> bom.save()
>>> routing = Routing(name="product")
>>> routing.boms.append(BoM(bom.id))
>>> routing.save()
>>> _ = product.boms.new(bom=bom, routing=routing)
>>> product.save()
Sale 10 products::
>>> sale = Sale()
>>> sale.party = customer
>>> sale.invoice_method = 'manual'
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 10
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
Check the production::
>>> production, = Production.find([])
>>> production.state
'request'
>>> assertEqual(production.product, product)
>>> assertEqual(production.bom, bom)
>>> assertEqual(production.routing, routing)