Initial commit of mrp_bom_add for 12.0

This commit is contained in:
Jared Kipe
2019-01-15 14:14:38 -08:00
parent 568c4c3b11
commit e838c9df2b
7 changed files with 260 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import mrp_bom_add

View File

@@ -0,0 +1,69 @@
from odoo import api, fields, models
class ProgramOutputView(models.TransientModel):
_name = 'mrp.bom.add'
_description = 'BoM Add Wizard'
bom_id = fields.Many2one('mrp.bom', string='Bill of Materials')
bom_product_tmpl_id = fields.Many2one('product.template', string='BoM Product', related='bom_id.product_tmpl_id')
product_tmpl_id = fields.Many2one('product.template', string='Product')
product_variant_count = fields.Integer(string='Variant Count', compute='_compute_variant_count')
limit_possible = fields.Boolean(string='Limit to possible variants',
help='Only add variants that can be selected by BoM Product')
product_qty = fields.Float(string='Quantity to Consume', default=1.0)
product_uom_id = fields.Many2one('uom.uom', string='Consume Unit of Measure')
bom_routing_id = fields.Many2one('mrp.routing', related='bom_id.routing_id')
operation_id = fields.Many2one('mrp.routing.workcenter', 'Consume in Operation')
@api.multi
@api.depends('product_tmpl_id', 'limit_possible')
def _compute_variant_count(self):
self.ensure_one()
if not self.product_tmpl_id or not self.bom_product_tmpl_id:
self.product_variant_count = 0
else:
products = self._compute_product_ids()
self.product_variant_count = len(products)
@api.onchange('product_tmpl_id')
def _onchange_default_product_uom(self):
if self.product_tmpl_id:
self.product_uom_id = self.product_tmpl_id.uom_id
def _compute_attribute_value_ids(self):
attr_val_ids = self.env['product.attribute.value']
other_val_ids = self.product_tmpl_id.mapped('attribute_line_ids.value_ids')
if not self.limit_possible:
return other_val_ids
main_product_value_ids = self.bom_product_tmpl_id.mapped('attribute_line_ids.value_ids')
for v in other_val_ids:
if v in main_product_value_ids:
attr_val_ids += v
return attr_val_ids
def _compute_product_ids(self):
values = self._compute_attribute_value_ids()
products = self.env['product.product']
for p in self.product_tmpl_id.product_variant_ids:
if not p.attribute_value_ids.filtered(lambda a: a not in values):
# This product's attribute values are in the values set.
products += p
return products
def add_variants(self):
attribute_values = self._compute_attribute_value_ids()
products = self._compute_product_ids()
if not self.product_uom_id:
self.product_uom_id = self.product_tmpl_id.uom_id
lines = []
for p in products:
lines.append((0, 0, {
'bom_id': self.bom_id.id,
'product_id': p.id,
'product_qty': self.product_qty,
'product_uom_id': self.product_uom_id.id,
'attribute_value_ids': [(4, a.id, 0) for a in p.attribute_value_ids if a in attribute_values],
'operation_id': self.operation_id.id,
}))
self.bom_id.write({'bom_line_ids': lines})

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_mrp_bom_add_form_view" model="ir.ui.view">
<field name="name">mrp.bom.add.form</field>
<field name="model">mrp.bom.add</field>
<field name="arch" type="xml">
<form string="Add to Bill of Materials">
<group>
<group>
<field name="bom_id" invisible="1"/>
<field name="bom_product_tmpl_id" invisible="1"/>
<field name="bom_routing_id" invisible="1"/>
<field name="product_tmpl_id"/>
<field name="limit_possible"/>
<field name="product_variant_count"/>
</group>
<group>
<field name="product_qty"/>
<field name="product_uom_id"/>
<field name="operation_id" domain="[('routing_id', '=', bom_routing_id)]"/>
</group>
</group>
<footer>
<button string="Add" class="btn-primary" type="object" name="add_variants"/>
</footer>
</form>
</field>
</record>
<record id="action_mrp_bom_add" model="ir.actions.act_window">
<field name="name">Add to Bill of Materials</field>
<field name="res_model">mrp.bom.add</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_mrp_bom_add_form_view"/>
<field name="target">new</field>
</record>
<record id="mrp_bom_form_view_inherit" model="ir.ui.view">
<field name="name">mrp.bom.form.inherit</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bom_line_ids']" position="after">
<button string="Add Bulk" type="action" name="%(mrp_bom_add.action_mrp_bom_add)d" context="{'default_bom_id': id}"/>
</xpath>
</field>
</record>
</odoo>