Make bom a functional field and add an option to open all boms for the nutrition program
This commit is contained in:
parent
569c225540
commit
becbaa88ed
|
@ -9,3 +9,6 @@ def register():
|
|||
Pool.register(
|
||||
NutritionProgram,
|
||||
module='nutrition_program', type_='model')
|
||||
Pool.register(
|
||||
OpenBOM,
|
||||
module='nutrition_program', type_='wizard')
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#The COPYRIGHT file at the top level of this repository contains the full
|
||||
#copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, PYSONEncoder
|
||||
from trytond.wizard import Wizard, StateAction
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['NutritionProgram']
|
||||
__all__ = ['NutritionProgram', 'OpenBOM']
|
||||
|
||||
|
||||
class NutritionProgram(ModelSQL, ModelView):
|
||||
|
@ -13,12 +16,40 @@ class NutritionProgram(ModelSQL, ModelView):
|
|||
start_weight = fields.Float('Start Weight')
|
||||
end_weight = fields.Float('End Weight')
|
||||
product = fields.Many2One('product.product', 'Product', required=True)
|
||||
bom = fields.Many2One('production.bom', 'BOM',
|
||||
bom = fields.Function(fields.Many2One('production.bom', 'BOM',
|
||||
domain=[
|
||||
('output_products', '=', Eval('product', 0)),
|
||||
],
|
||||
depends=['product'])
|
||||
depends=['product']), 'get_bom')
|
||||
|
||||
def get_bom(self, name):
|
||||
if self.product and self.product.boms:
|
||||
return self.product.boms[0].bom.id
|
||||
|
||||
def get_rec_name(self, name=None):
|
||||
return ' %s ( %s - %s) ' % (self.product.rec_name,
|
||||
self.start_weight or '', self.end_weight or '')
|
||||
|
||||
|
||||
class OpenBOM(Wizard):
|
||||
'Open BOM'
|
||||
__name__ = 'nutrition.program.open.bom'
|
||||
start_state = 'open_'
|
||||
open_ = StateAction('production.act_bom_list')
|
||||
|
||||
def do_open_(self, action):
|
||||
pool = Pool()
|
||||
NutritionProgram = pool.get('nutrition.program')
|
||||
|
||||
program = NutritionProgram(Transaction().context.get('active_id'))
|
||||
|
||||
bom_ids = []
|
||||
if program.product.boms:
|
||||
bom_ids = [bom.bom.id for bom in program.product.boms]
|
||||
action['pyson_domain'] = PYSONEncoder().encode(
|
||||
[('id', 'in', bom_ids)])
|
||||
|
||||
return action, {}
|
||||
|
||||
def transition_open_(self):
|
||||
return 'end'
|
||||
|
|
|
@ -70,5 +70,16 @@
|
|||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="wizard_bom_open">
|
||||
<field name="name">BOMs</field>
|
||||
<field name="wiz_name">nutrition.program.open.bom</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword"
|
||||
id="act_nutrition_program_open_keyword1">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">nutrition.program,-1</field>
|
||||
<field name="action" ref="wizard_bom_open"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in New Issue