Skip to content

Commit

Permalink
enable MRP view in product templates
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow authored and LoisRForgeFlow committed Aug 30, 2018
1 parent 17342ca commit f286625
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mrp_multi_level/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
'security/mrp_multi_level_security.xml',
'security/ir.model.access.csv',
'views/mrp_area_view.xml',
'views/product_view.xml',
'views/product_product_view.xml',
'views/product_template_view.xml',
'views/stock_location_view.xml',
'views/mrp_product_view.xml',
'wizards/mrp_inventory_procure_view.xml',
Expand Down
3 changes: 2 additions & 1 deletion mrp_multi_level/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import mrp_area
from . import stock_location
from . import product
from . import product_product
from . import product_template
from . import mrp_product
from . import mrp_move
from . import mrp_inventory
File renamed without changes.
228 changes: 228 additions & 0 deletions mrp_multi_level/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

mrp_applicable = fields.Boolean(string='MRP Applicable',
compute='_compute_mrp_applicable',
inverse='_set_mrp_applicable', store=True
)
mrp_exclude = fields.Boolean(string='Exclude from MRP',
compute='_compute_mrp_exclude',
inverse='_set_mrp_exclude', store=True
)
mrp_inspection_delay = fields.Integer(
string='Inspection Delay',
compute='_compute_mrp_inspection_delay',
inverse='_set_mrp_inspection_delay',
store=True
)
mrp_maximum_order_qty = fields.Float(
string='Maximum Order Qty',
compute='_compute_mrp_maximum_order_qty',
inverse='_set_mrp_maximum_order_qty', store=True
)
mrp_minimum_order_qty = fields.Float(
string='Minimum Order Qty',
compute='_compute_mrp_minimum_order_qty',
inverse='_set_mrp_minimum_order_qty', store=True
)
mrp_minimum_stock = fields.Float(
string='Minimum Stock',
compute='_compute_mrp_minimum_stock',
inverse='_set_mrp_minimum_stock', store=True
)
mrp_nbr_days = fields.Integer(
string='Nbr. Days',
compute='_compute_mrp_nbr_days',
inverse='_set_mrp_nbr_days', store=True,
help="Number of days to group demand for this product during the "
"MRP run, in order to determine the quantity to order.",
)
mrp_qty_multiple = fields.Float(
string='Qty Multiple', default=1.00,
compute='_compute_mrp_qty_multiple',
inverse='_set_mrp_qty_multiple', store=True
)
mrp_transit_delay = fields.Integer(
string='Transit Delay', default=0,
compute='_compute_mrp_transit_delay',
inverse='_set_mrp_transit_delay', store=True
)
mrp_verified = fields.Boolean(
string='Verified for MRP',
compute='_compute_mrp_verified',
inverse='_set_mrp_verified', store=True,
help="Identifies that this product has been verified "
"to be valid for the MRP.",
)

@api.depends('product_variant_ids', 'product_variant_ids.mrp_applicable')
def _compute_mrp_applicable(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_applicable = \
template.product_variant_ids.mrp_applicable
for template in (self - unique_variants):
template.mrp_applicable = False

@api.one
def _set_mrp_applicable(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_applicable = self.mrp_applicable

@api.depends('product_variant_ids', 'product_variant_ids.mrp_exclude')
def _compute_mrp_exclude(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_exclude = \
template.product_variant_ids.mrp_exclude
for template in (self - unique_variants):
template.mrp_exclude = False

@api.one
def _set_mrp_exclude(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_exclude = self.mrp_exclude

@api.depends('product_variant_ids',
'product_variant_ids.mrp_inspection_delay')
def _compute_mrp_inspection_delay(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_inspection_delay = \
template.product_variant_ids.mrp_inspection_delay
for template in (self - unique_variants):
template.mrp_inspection_delay = 0

@api.one
def _set_mrp_inspection_delay(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_inspection_delay = \
self.mrp_inspection_delay

@api.depends('product_variant_ids',
'product_variant_ids.mrp_maximum_order_qty')
def _compute_mrp_maximum_order_qty(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_maximum_order_qty = \
template.product_variant_ids.mrp_maximum_order_qty
for template in (self - unique_variants):
template.mrp_maximum_order_qty = 0.0

@api.one
def _set_mrp_maximum_order_qty(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_maximum_order_qty = \
self.mrp_maximum_order_qty

@api.depends('product_variant_ids',
'product_variant_ids.mrp_minimum_order_qty')
def _compute_mrp_minimum_order_qty(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_minimum_order_qty = \
template.product_variant_ids.mrp_minimum_order_qty
for template in (self - unique_variants):
template.mrp_minimum_order_qty = 0.0

@api.one
def _set_mrp_minimum_order_qty(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_minimum_order_qty = \
self.mrp_minimum_order_qty

@api.depends('product_variant_ids',
'product_variant_ids.mrp_minimum_stock')
def _compute_mrp_minimum_stock(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_minimum_stock = \
template.product_variant_ids.mrp_minimum_stock
for template in (self - unique_variants):
template.mrp_minimum_stock = 0.0

@api.one
def _set_mrp_minimum_stock(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_minimum_stock = \
self.mrp_minimum_stock

@api.depends('product_variant_ids',
'product_variant_ids.mrp_nbr_days')
def _compute_mrp_nbr_days(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_nbr_days = \
template.product_variant_ids.mrp_nbr_days
for template in (self - unique_variants):
template.mrp_nbr_days = 0.0

@api.one
def _set_mrp_nbr_days(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_nbr_days = \
self.mrp_nbr_days

@api.depends('product_variant_ids',
'product_variant_ids.mrp_qty_multiple')
def _compute_mrp_qty_multiple(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_qty_multiple = \
template.product_variant_ids.mrp_qty_multiple
for template in (self - unique_variants):
template.mrp_qty_multiple = 1

@api.one
def _set_mrp_qty_multiple(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_qty_multiple = \
self.mrp_qty_multiple

@api.depends('product_variant_ids',
'product_variant_ids.mrp_transit_delay')
def _compute_mrp_transit_delay(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_transit_delay = \
template.product_variant_ids.mrp_transit_delay
for template in (self - unique_variants):
template.mrp_transit_delay = 0.0

@api.one
def _set_mrp_transit_delay(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_transit_delay = \
self.mrp_transit_delay

@api.depends('product_variant_ids',
'product_variant_ids.mrp_verified')
def _compute_mrp_verified(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_verified = \
template.product_variant_ids.mrp_verified
for template in (self - unique_variants):
template.mrp_verified = 0.0

@api.one
def _set_mrp_verified(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_verified = \
self.mrp_verified
File renamed without changes.
31 changes: 31 additions & 0 deletions mrp_multi_level/views/product_template_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<odoo>

<record id="product_template_only_form_view_mrp" model="ir.ui.view">
<field name="name">product.template.product.form.mrp</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<notebook position="inside">
<page name="mrp_multi_level" string="MRP" attrs="{'invisible': [('product_variant_count', '&gt;', 1)]}">
<group colspan="4" col="2">
<group>
<field name="mrp_exclude"/>
<field name="mrp_verified"/>
<field name="mrp_nbr_days"/>
<field name="mrp_transit_delay"/>
<field name="mrp_inspection_delay"/>
</group>
<group>
<field name="mrp_minimum_stock"/>
<field name="mrp_minimum_order_qty"/>
<field name="mrp_maximum_order_qty"/>
<field name="mrp_qty_multiple"/>
</group>
</group>
</page>
</notebook>
</field>
</record>

</odoo>

0 comments on commit f286625

Please sign in to comment.