Add additional products in packaging. Task 039466
This commit is contained in:
parent
eb0b4c5898
commit
ac1d202b81
|
@ -9,6 +9,7 @@ module = 'product_bulk'
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
product.ExtraProductPackaging,
|
||||||
product.Product,
|
product.Product,
|
||||||
product.TemplateProductPackaging,
|
product.TemplateProductPackaging,
|
||||||
product.Template,
|
product.Template,
|
||||||
|
|
46
product.py
46
product.py
|
@ -9,7 +9,8 @@ from trytond.wizard import (Wizard, StateAction, StateView, StateTransition,
|
||||||
Button)
|
Button)
|
||||||
from trytond.exceptions import UserWarning
|
from trytond.exceptions import UserWarning
|
||||||
|
|
||||||
__all__ = ['Template', 'Product', 'TemplateProductPackaging']
|
__all__ = ['Template', 'Product', 'TemplateProductPackaging',
|
||||||
|
'ExtraProductPackaging']
|
||||||
|
|
||||||
from trytond.modules.product.product import STATES, DEPENDS
|
from trytond.modules.product.product import STATES, DEPENDS
|
||||||
|
|
||||||
|
@ -34,6 +35,28 @@ class TemplateProductPackaging(ModelSQL, ModelView):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class ExtraProductPackaging(ModelSQL, ModelView):
|
||||||
|
"Template - Product Packaging"
|
||||||
|
__name__ = 'product.template-extra.product'
|
||||||
|
_rec_name = 'packaging_product'
|
||||||
|
extra_product = fields.Many2One('product.template', 'Extra Product',
|
||||||
|
required=True, ondelete='CASCADE',
|
||||||
|
states = {
|
||||||
|
'readonly': Bool(Eval('packaged_product')),
|
||||||
|
})
|
||||||
|
product = fields.Many2One('product.template', 'Product', required=True)
|
||||||
|
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||||
|
'on_change_with_unit_digits')
|
||||||
|
quantity = fields.Float('Quantity',
|
||||||
|
digits=(16, Eval('unit_digits', 2)),
|
||||||
|
depends=['unit_digits'])
|
||||||
|
|
||||||
|
@fields.depends('product')
|
||||||
|
def on_change_with_unit_digits(self, name=None):
|
||||||
|
if self.extra_product.default_uom:
|
||||||
|
return self.extra_product.default_uom.digits
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
class Template(metaclass=PoolMeta):
|
class Template(metaclass=PoolMeta):
|
||||||
__name__ = 'product.template'
|
__name__ = 'product.template'
|
||||||
|
@ -86,6 +109,11 @@ class Template(metaclass=PoolMeta):
|
||||||
depends=['type', 'netweight'])
|
depends=['type', 'netweight'])
|
||||||
netweight_digits = fields.Function(fields.Integer('Net Weight Digits'),
|
netweight_digits = fields.Function(fields.Integer('Net Weight Digits'),
|
||||||
'on_change_with_netweight_digits')
|
'on_change_with_netweight_digits')
|
||||||
|
extra_products = fields.One2Many('product.template-extra.product',
|
||||||
|
'product', 'Extra Products',
|
||||||
|
states = {
|
||||||
|
'readonly': (~Eval('active', True) | Eval('bulk_type') != True),
|
||||||
|
})
|
||||||
|
|
||||||
def sum_product(self, name):
|
def sum_product(self, name):
|
||||||
if name in ('bulk_quantity'):
|
if name in ('bulk_quantity'):
|
||||||
|
@ -155,6 +183,7 @@ class Template(metaclass=PoolMeta):
|
||||||
product_to_save = []
|
product_to_save = []
|
||||||
bom_to_save = []
|
bom_to_save = []
|
||||||
output_to_save = []
|
output_to_save = []
|
||||||
|
inputs = []
|
||||||
|
|
||||||
for bulk_product in products:
|
for bulk_product in products:
|
||||||
for package_product in bulk_product.packaging_products:
|
for package_product in bulk_product.packaging_products:
|
||||||
|
@ -214,17 +243,30 @@ class Template(metaclass=PoolMeta):
|
||||||
product=bulk_product.products[0].id,
|
product=bulk_product.products[0].id,
|
||||||
uom=bulk_product.default_uom,
|
uom=bulk_product.default_uom,
|
||||||
quantity=netweight)
|
quantity=netweight)
|
||||||
|
inputs.append(bulk_input)
|
||||||
package_input = BOMInput(
|
package_input = BOMInput(
|
||||||
bom=bom,
|
bom=bom,
|
||||||
product=package_product.packaging_product.id,
|
product=package_product.packaging_product.id,
|
||||||
uom=package_product.packaging_product.default_uom,
|
uom=package_product.packaging_product.default_uom,
|
||||||
quantity=1.0)
|
quantity=1.0)
|
||||||
|
inputs.append(package_input)
|
||||||
|
|
||||||
|
if bulk_product.extra_products:
|
||||||
|
for extra in bulk_product.extra_products:
|
||||||
|
extra_input = BOMInput(
|
||||||
|
bom=bom,
|
||||||
|
product=extra.extra_product.products[0].id,
|
||||||
|
uom=extra.extra_product.default_uom,
|
||||||
|
quantity=extra.quantity)
|
||||||
|
inputs.append(extra_input)
|
||||||
|
|
||||||
output = BOMOutput(
|
output = BOMOutput(
|
||||||
bom=bom,
|
bom=bom,
|
||||||
product=output_product.id,
|
product=output_product.id,
|
||||||
uom=uom_unit,
|
uom=uom_unit,
|
||||||
quantity=1.0)
|
quantity=1.0)
|
||||||
bom.inputs = [bulk_input, package_input]
|
|
||||||
|
bom.inputs = inputs
|
||||||
bom.outputs = [output]
|
bom.outputs = [output]
|
||||||
bom_to_save.append(bom)
|
bom_to_save.append(bom)
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,12 @@
|
||||||
<record model="ir.ui.view" id="product_packaging_view_list">
|
<record model="ir.ui.view" id="product_packaging_view_list">
|
||||||
<field name="model">product.template-product.packaging</field>
|
<field name="model">product.template-product.packaging</field>
|
||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="priority" eval="20"/>
|
|
||||||
<field name="name">product_packaging_list</field>
|
<field name="name">product_packaging_list</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="ir.ui.view" id="product_extra_packaging_view_list">
|
||||||
|
<field name="model">product.template-extra.product</field>
|
||||||
|
<field name="type">tree</field>
|
||||||
|
<field name="name">product_extra_packaging_list</field>
|
||||||
|
</record>
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||||
|
this repository contains the full copyright notices and license terms. -->
|
||||||
|
<tree editable="bottom">
|
||||||
|
<field name="extra_product"/>
|
||||||
|
<field name="quantity"/>
|
||||||
|
</tree>
|
|
@ -29,7 +29,9 @@
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="/form/notebook" position="inside">
|
<xpath expr="/form/notebook" position="inside">
|
||||||
<page id="packaging_products" string="Packaging Products">
|
<page id="packaging_products" string="Packaging Products">
|
||||||
<field name="packaging_products" colspan="4"/>
|
<field name="packaging_products" colspan="4"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="extra_products" colspan="4"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<button name="create_packaging_products"
|
<button name="create_packaging_products"
|
||||||
string="Create packaging products" colspan="2"/>
|
string="Create packaging products" colspan="2"/>
|
||||||
|
|
Loading…
Reference in New Issue