[IMP] mrp: Convert yml demo and data files to python

This commit is contained in:
Yannick Tivisse
2017-11-16 14:49:05 +01:00
parent bf732d9614
commit 4516b1b02b
5 changed files with 42 additions and 27 deletions
+1 -2
View File
@@ -15,7 +15,6 @@
'security/mrp_security.xml',
'security/ir.model.access.csv',
'data/mrp_data.xml',
'data/mrp_data.yml',
'wizard/mrp_product_produce_views.xml',
'wizard/change_production_qty_views.xml',
'wizard/mrp_workcenter_block_view.xml',
@@ -44,7 +43,7 @@
],
'demo': [
'data/mrp_demo.xml',
'data/mrp_lot_demo.yml'],
],
'qweb': ['static/src/xml/mrp.xml'],
'test': [],
'application': True,
+17
View File
@@ -82,5 +82,22 @@
<field name="manual" eval="False"/>
<field name="sequence">0</field>
</record>
<function model="ir.model.data" name="create">
<value model="stock.warehouse" eval="{
'name': 'picking_type_manufacturing',
'module':'mrp',
'model': 'stock.picking.type',
'res_id': obj().env.ref('stock.warehouse0').manu_type_id.id,
}"/>
</function>
<!-- avoid the xml id and the associated resource being dropped by the orm by manually making a hit on it -->
<function model="ir.model.data" name="_update_dummy">
<value>stock.picking.type</value>
<value>mrp</value>
<value>picking_type_manufacturing</value>
</function>
</data>
</odoo>
-13
View File
@@ -1,13 +0,0 @@
-
!python {model: ir.model.data, id: False}: |
warehouse = self.env['stock.warehouse'].browse(ref('stock.warehouse0'))
#create xml ids for demo data that are widely used in tests or in other codes, for more convenience
xml_references = [
{'name':'picking_type_manufacturing','module':'mrp', 'model':'stock.picking.type','res_id': warehouse.manu_type_id.id},
]
for xml_record in xml_references:
xml_ids = self.search([('module', '=', xml_record['module']), ('model', '=', xml_record['model']), ('name', '=', xml_record['name'])]).ids
if not xml_ids:
self.create(xml_record)
#avoid the xml id and the associated resource being dropped by the orm by manually making a hit on it
self._update_dummy(xml_record['model'], xml_record['module'], xml_record['name'])
+24
View File
@@ -588,7 +588,31 @@
<field name="date_start" eval="(datetime.now() - timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
</record>
<function model="mrp.production" name="action_assign">
<value eval="[ref('mrp.mrp_production_laptop_cust')]"/>
</function>
<function model="mrp.product.produce" name="create">
<value model="mrp.product.produce" eval="dict(
obj().with_context(active_id=ref('mrp.mrp_production_laptop_cust')).default_get(list(obj().fields_get())),
**{
'product_qty': obj().env.ref('mrp.mrp_production_laptop_cust').product_qty,
'lot_id': ref('mrp.lot_product_27_0'),
}
)"/>
</function>
<function model="mrp.product.produce" name="do_produce">
<value model="mrp.product.produce" search="[('production_id', '=', obj().env.ref('mrp.mrp_production_laptop_cust').id)]"/>
</function>
<function model="mrp.production" name="post_inventory">
<value eval="[ref('mrp.mrp_production_laptop_cust')]"/>
</function>
<function model="mrp.production" name="button_mark_done">
<value eval="[ref('mrp.mrp_production_laptop_cust')]"/>
</function>
</data>
</odoo>
-12
View File
@@ -1,12 +0,0 @@
-
!python {model: mrp.production, id: mrp_production_laptop_cust}: |
if self.state != 'done':
self.action_assign()
wiz_obj = self.env['mrp.product.produce']
ctx = dict(self.env.context, active_id=self.id)
produce_wiz = wiz_obj.with_context(ctx).create({'product_qty': self.product_qty, 'lot_id': ref('lot_product_27_0')})
produce_wiz.produce_line_ids.write({'qty_done': produce_wiz.product_qty})
#Produce Product,Post Inventory and Set MO Done.
produce_wiz.do_produce()
self.post_inventory()
self.button_mark_done()