Add code to production BOM
This commit is contained in:
1 parent
c1f3ddcd10
commit
215834f78f
7 files changed
+99
-3
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add code to BOM
|
||||
|
||||
Version 7.2.0 - 2024-04-29
|
||||
--------------------------
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from sql.functions import CharLength
|
||||
|
||||
from trytond.model import DeactivableMixin, ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tools import is_full_text, lstrip_wildcard
|
||||
from trytond.wizard import Button, StateView, Wizard
|
||||
|
||||
|
||||
@@ -11,11 +15,62 @@ class BOM(DeactivableMixin, ModelSQL, ModelView):
|
||||
__name__ = 'production.bom'
|
||||
|
||||
name = fields.Char('Name', required=True, translate=True)
|
||||
code = fields.Char(
|
||||
"Code",
|
||||
states={
|
||||
'readonly': Eval('code_readonly', False),
|
||||
})
|
||||
code_readonly = fields.Function(
|
||||
fields.Boolean("Code Readonly"), 'get_code_readonly')
|
||||
inputs = fields.One2Many('production.bom.input', 'bom', 'Inputs')
|
||||
outputs = fields.One2Many('production.bom.output', 'bom', 'Outputs')
|
||||
output_products = fields.Many2Many('production.bom.output',
|
||||
'bom', 'product', 'Output Products')
|
||||
|
||||
@classmethod
|
||||
def order_code(cls, tables):
|
||||
table, _ = tables[None]
|
||||
if cls.default_code_readonly():
|
||||
return [CharLength(table.code), table.code]
|
||||
else:
|
||||
return [table.code]
|
||||
|
||||
@classmethod
|
||||
def default_code_readonly(cls):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('production.configuration')
|
||||
config = Configuration(1)
|
||||
return bool(config.bom_sequence)
|
||||
|
||||
def get_code_readonly(self, name):
|
||||
return self.default_code_readonly()
|
||||
|
||||
@classmethod
|
||||
def order_rec_name(cls, tables):
|
||||
table, _ = tables[None]
|
||||
return cls.order_code(tables) + [table.name]
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.code:
|
||||
return '[' + self.code + '] ' + self.name
|
||||
else:
|
||||
return self.name
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
_, operator, operand, *extra = clause
|
||||
if operator.startswith('!') or operator.startswith('not '):
|
||||
bool_op = 'AND'
|
||||
else:
|
||||
bool_op = 'OR'
|
||||
code_value = operand
|
||||
if operator.endswith('like') and is_full_text(operand):
|
||||
code_value = lstrip_wildcard(operand)
|
||||
return [bool_op,
|
||||
('name', operator, operand, *extra),
|
||||
('code', operator, code_value, *extra),
|
||||
]
|
||||
|
||||
def compute_factor(self, product, quantity, unit):
|
||||
'''
|
||||
Compute factor for an output product
|
||||
@@ -31,12 +86,30 @@ class BOM(DeactivableMixin, ModelSQL, ModelView):
|
||||
else:
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def _new_code(cls):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('production.configuration')
|
||||
config = Configuration(1)
|
||||
sequence = config.bom_sequence
|
||||
if sequence:
|
||||
return sequence.get()
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
vlist = [v.copy() for v in vlist]
|
||||
for values in vlist:
|
||||
if not values.get('code'):
|
||||
values['code'] = cls._new_code()
|
||||
return super().create(vlist)
|
||||
|
||||
@classmethod
|
||||
def copy(cls, records, default=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
else:
|
||||
default = default.copy()
|
||||
default.setdefault('code', None)
|
||||
default.setdefault('output_products', None)
|
||||
return super(BOM, cls).copy(records, default=default)
|
||||
|
||||
|
||||
@@ -136,5 +136,16 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="action" ref="act_product_in_bom"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.sequence.type" id="sequence_type_bom">
|
||||
<field name="name">BOM</field>
|
||||
</record>
|
||||
<record model="ir.sequence.type-res.group" id="sequence_type_bom_group_admin">
|
||||
<field name="sequence_type" ref="sequence_type_bom"/>
|
||||
<field name="group" ref="res.group_admin"/>
|
||||
</record>
|
||||
<record model="ir.sequence.type-res.group" id="sequence_type_bom_group_production_admin">
|
||||
<field name="sequence_type" ref="sequence_type_bom"/>
|
||||
<field name="group" ref="group_production_admin"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -20,6 +20,12 @@ class Configuration(
|
||||
('sequence_type', '=',
|
||||
Id('production', 'sequence_type_production')),
|
||||
]))
|
||||
bom_sequence = fields.Many2One(
|
||||
'ir.sequence', "BOM Sequence",
|
||||
domain=[
|
||||
('sequence_type', '=', Id('production', 'sequence_type_bom')),
|
||||
],
|
||||
help="Used to generate the BOM code.")
|
||||
|
||||
@classmethod
|
||||
def default_production_sequence(cls, **pattern):
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?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. -->
|
||||
<form>
|
||||
<form col="6">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="code"/>
|
||||
<field name="code"/>
|
||||
<label name="active"/>
|
||||
<field name="active"/>
|
||||
<field name="active" xexpand="0" width="100"/>
|
||||
<notebook>
|
||||
<page string="Lines" id="lines" col="2">
|
||||
<field name="inputs"/>
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<!-- 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>
|
||||
<field name="name" expand="1"/>
|
||||
<field name="code" expand="1"/>
|
||||
<field name="name" expand="2"/>
|
||||
</tree>
|
||||
@@ -4,4 +4,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="production_sequence"/>
|
||||
<field name="production_sequence"/>
|
||||
<label name="bom_sequence"/>
|
||||
<field name="bom_sequence"/>
|
||||
</form>
|
||||
Reference in new issue
Block a user