mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[11.0][mrp_multi_level] refactor mrp area
This commit is contained in:
@@ -2,6 +2,6 @@ from . import mrp_area
|
||||
from . import stock_location
|
||||
from . import product_product
|
||||
from . import product_template
|
||||
from . import mrp_product
|
||||
from . import mrp_move
|
||||
from . import mrp_inventory
|
||||
from . import product_mrp_area
|
||||
|
||||
@@ -10,9 +10,9 @@ from datetime import timedelta, date
|
||||
|
||||
class MrpInventory(models.Model):
|
||||
_name = 'mrp.inventory'
|
||||
_order = 'mrp_product_id, date'
|
||||
_order = 'product_mrp_area_id, date'
|
||||
_description = 'MRP inventory projections'
|
||||
_rec_name = 'mrp_product_id'
|
||||
_rec_name = 'product_mrp_area_id'
|
||||
|
||||
# TODO: name to pass to procurements?
|
||||
# TODO: compute procurement_date to pass to the wizard? not needed for
|
||||
@@ -22,10 +22,10 @@ class MrpInventory(models.Model):
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name='mrp.area', string='MRP Area',
|
||||
related='mrp_product_id.mrp_area_id', store=True,
|
||||
related='product_mrp_area_id.mrp_area_id', store=True,
|
||||
)
|
||||
mrp_product_id = fields.Many2one(
|
||||
comodel_name='mrp.product', string='Product',
|
||||
product_mrp_area_id = fields.Many2one(
|
||||
comodel_name='product.mrp.area', string='Product',
|
||||
index=True,
|
||||
)
|
||||
uom_id = fields.Many2one(
|
||||
@@ -47,20 +47,21 @@ class MrpInventory(models.Model):
|
||||
@api.multi
|
||||
def _compute_uom_id(self):
|
||||
for rec in self:
|
||||
rec.uom_id = rec.mrp_product_id.product_id.uom_id
|
||||
rec.uom_id = rec.product_mrp_area_id.product_id.uom_id
|
||||
|
||||
@api.multi
|
||||
@api.depends('mrp_product_id', 'mrp_product_id.main_supplierinfo_id',
|
||||
'mrp_product_id.mrp_lead_time',
|
||||
'mrp_product_id.mrp_area_id.calendar_id')
|
||||
@api.depends('product_mrp_area_id',
|
||||
'product_mrp_area_id.main_supplierinfo_id',
|
||||
'product_mrp_area_id.mrp_lead_time',
|
||||
'product_mrp_area_id.mrp_area_id.calendar_id')
|
||||
def _compute_order_release_date(self):
|
||||
today = date.today()
|
||||
for rec in self.filtered(lambda r: r.date):
|
||||
delay = 0
|
||||
if rec.mrp_product_id.supply_method == 'buy':
|
||||
delay = rec.mrp_product_id.main_supplierinfo_id.delay
|
||||
elif rec.mrp_product_id.supply_method == 'manufacture':
|
||||
delay = rec.mrp_product_id.mrp_lead_time
|
||||
if rec.product_mrp_area_id.supply_method == 'buy':
|
||||
delay = rec.product_mrp_area_id.main_supplierinfo_id.delay
|
||||
elif rec.product_mrp_area_id.supply_method == 'manufacture':
|
||||
delay = rec.product_mrp_area_id.mrp_lead_time
|
||||
# TODO: 'move' supply method
|
||||
if delay and rec.mrp_area_id.calendar_id:
|
||||
dt_date = fields.Datetime.from_string(rec.date)
|
||||
|
||||
@@ -7,13 +7,16 @@ from odoo import models, fields
|
||||
|
||||
class MrpMove(models.Model):
|
||||
_name = 'mrp.move'
|
||||
_order = 'mrp_product_id, mrp_date, mrp_type desc, id'
|
||||
_order = 'product_mrp_area_id, mrp_date, mrp_type desc, id'
|
||||
|
||||
# TODO: too many indexes...
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name='mrp.area',
|
||||
related='product_mrp_area_id.mrp_area_id',
|
||||
string='MRP Area',
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
current_date = fields.Date(string='Current Date')
|
||||
current_qty = fields.Float(string='Current Qty')
|
||||
@@ -43,7 +46,7 @@ class MrpMove(models.Model):
|
||||
)
|
||||
mrp_minimum_stock = fields.Float(
|
||||
string='Minimum Stock',
|
||||
related='product_id.mrp_minimum_stock',
|
||||
related='product_mrp_area_id.mrp_minimum_stock',
|
||||
)
|
||||
mrp_order_number = fields.Char(string='Order Number')
|
||||
# TODO: replace by a char origin?
|
||||
@@ -54,8 +57,8 @@ class MrpMove(models.Model):
|
||||
('fc', 'Forecast'), ('mrp', 'MRP')],
|
||||
string='Origin')
|
||||
mrp_processed = fields.Boolean(string='Processed')
|
||||
mrp_product_id = fields.Many2one(
|
||||
comodel_name='mrp.product',
|
||||
product_mrp_area_id = fields.Many2one(
|
||||
comodel_name='product.mrp.area',
|
||||
string='Product', index=True,
|
||||
)
|
||||
mrp_qty = fields.Float(string='MRP Quantity')
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
# © 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
|
||||
# © 2016-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from math import ceil
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MrpProduct(models.Model):
|
||||
_name = 'mrp.product'
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name='mrp.area', string='MRP Area',
|
||||
)
|
||||
current_qty_available = fields.Float(
|
||||
string='Current Qty Available',
|
||||
related='product_id.qty_available',
|
||||
)
|
||||
main_supplier_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Main Supplier',
|
||||
compute='_compute_main_supplier', store=True,
|
||||
index=True,
|
||||
)
|
||||
main_supplierinfo_id = fields.Many2one(
|
||||
comodel_name='product.supplierinfo', string='Supplier Info',
|
||||
compute='_compute_main_supplier', store=True,
|
||||
)
|
||||
mrp_inspection_delay = fields.Integer(
|
||||
string='Inspection Delay',
|
||||
related='product_id.mrp_inspection_delay')
|
||||
mrp_lead_time = fields.Float(
|
||||
string='Lead Time',
|
||||
related='product_id.produce_delay',
|
||||
)
|
||||
mrp_llc = fields.Integer(
|
||||
string='Low Level Code', index=True, readonly=True,
|
||||
)
|
||||
# TODO: minimun stock and max/min order qty assigned by area?
|
||||
mrp_maximum_order_qty = fields.Float(
|
||||
string='Maximum Order Qty',
|
||||
related='product_id.mrp_maximum_order_qty',
|
||||
)
|
||||
mrp_minimum_order_qty = fields.Float(
|
||||
string='Minimum Order Qty',
|
||||
related='product_id.mrp_minimum_order_qty',
|
||||
)
|
||||
mrp_minimum_stock = fields.Float(
|
||||
string='Minimum Stock',
|
||||
related='product_id.mrp_minimum_stock',
|
||||
)
|
||||
mrp_move_ids = fields.One2many(
|
||||
comodel_name='mrp.move', inverse_name='mrp_product_id',
|
||||
string='MRP Moves',
|
||||
)
|
||||
mrp_nbr_days = fields.Integer(
|
||||
string='Nbr. Days', related='product_id.mrp_nbr_days')
|
||||
mrp_qty_available = fields.Float(
|
||||
string='MRP Qty Available')
|
||||
mrp_qty_multiple = fields.Float(
|
||||
string='Qty Multiple',
|
||||
related='product_id.mrp_qty_multiple',
|
||||
)
|
||||
mrp_transit_delay = fields.Integer(related='product_id.mrp_transit_delay')
|
||||
mrp_verified = fields.Boolean(
|
||||
string='MRP Verified',
|
||||
related='product_id.mrp_verified',
|
||||
)
|
||||
name = fields.Char(string='Description')
|
||||
# TODO: rename to mrp_action_count?
|
||||
nbr_mrp_actions = fields.Integer(
|
||||
string='Nbr Actions', index=True,
|
||||
)
|
||||
nbr_mrp_actions_4w = fields.Integer(
|
||||
string='Nbr Actions 4 Weeks', index=True,
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product', string='Product',
|
||||
index=True,
|
||||
)
|
||||
product_tmpl_id = fields.Many2one(
|
||||
comodel_name='product.template',
|
||||
string='Product Template',
|
||||
related='product_id.product_tmpl_id',
|
||||
)
|
||||
supply_method = fields.Selection(
|
||||
selection=[('buy', 'Buy'),
|
||||
('none', 'Undefined'),
|
||||
('manufacture', 'Produce'),
|
||||
('move', 'Transfer')],
|
||||
string='Supply Method',
|
||||
compute='_compute_supply_method', store=True,
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.depends('mrp_area_id')
|
||||
def _compute_supply_method(self):
|
||||
group_obj = self.env['procurement.group']
|
||||
for rec in self:
|
||||
values = {
|
||||
'warehouse_id': rec.mrp_area_id.warehouse_id,
|
||||
'company_id': self.env.user.company_id.id,
|
||||
# TODO: better way to get company
|
||||
}
|
||||
rule = group_obj._get_rule(
|
||||
rec.product_id, rec.mrp_area_id.location_id, values)
|
||||
rec.supply_method = rule.action if rule else 'none'
|
||||
|
||||
@api.multi
|
||||
@api.depends('supply_method')
|
||||
def _compute_main_supplier(self):
|
||||
"""Simplified and similar to procurement.rule logic."""
|
||||
for rec in self.filtered(lambda r: r.supply_method == 'buy'):
|
||||
suppliers = rec.product_id.seller_ids.filtered(
|
||||
lambda r: (not r.product_id or r.product_id == rec.product_id))
|
||||
if not suppliers:
|
||||
continue
|
||||
rec.main_supplierinfo_id = suppliers[0]
|
||||
rec.main_supplier_id = suppliers[0].name
|
||||
|
||||
@api.multi
|
||||
def _adjust_qty_to_order(self, qty_to_order):
|
||||
self.ensure_one()
|
||||
if (not self.mrp_maximum_order_qty and not
|
||||
self.mrp_minimum_order_qty and self.mrp_qty_multiple == 1.0):
|
||||
return qty_to_order
|
||||
if qty_to_order < self.mrp_minimum_order_qty:
|
||||
return self.mrp_minimum_order_qty
|
||||
if self.mrp_qty_multiple:
|
||||
multiplier = ceil(qty_to_order / self.mrp_qty_multiple)
|
||||
qty_to_order = multiplier * self.mrp_qty_multiple
|
||||
if self.mrp_maximum_order_qty and qty_to_order > \
|
||||
self.mrp_maximum_order_qty:
|
||||
return self.mrp_maximum_order_qty
|
||||
return qty_to_order
|
||||
143
mrp_multi_level/models/product_mrp_area.py
Normal file
143
mrp_multi_level/models/product_mrp_area.py
Normal file
@@ -0,0 +1,143 @@
|
||||
# Copyright 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
|
||||
# Copyright 2016-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
from math import ceil
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProductMRPArea(models.Model):
|
||||
_name = 'product.mrp.area'
|
||||
_description = 'Product MRP Area'
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
mrp_area_id = fields.Many2one('mrp.area',
|
||||
required=True,
|
||||
)
|
||||
product_id = fields.Many2one('product.product',
|
||||
required=True,
|
||||
string='Product',
|
||||
)
|
||||
product_tmpl_id = fields.Many2one('product.template',
|
||||
readonly=True,
|
||||
related='product_id.product_tmpl_id',
|
||||
store=True,
|
||||
)
|
||||
|
||||
# TODO: applicable and exclude... redundant??
|
||||
mrp_applicable = fields.Boolean(string='MRP Applicable')
|
||||
mrp_exclude = fields.Boolean(string='Exclude from MRP')
|
||||
mrp_inspection_delay = fields.Integer(string='Inspection Delay')
|
||||
mrp_maximum_order_qty = fields.Float(
|
||||
string='Maximum Order Qty', default=0.0,
|
||||
)
|
||||
mrp_minimum_order_qty = fields.Float(
|
||||
string='Minimum Order Qty', default=0.0,
|
||||
)
|
||||
mrp_minimum_stock = fields.Float(string='Minimum Stock')
|
||||
mrp_nbr_days = fields.Integer(
|
||||
string='Nbr. Days', default=0,
|
||||
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)
|
||||
mrp_transit_delay = fields.Integer(string='Transit Delay', default=0)
|
||||
mrp_verified = fields.Boolean(
|
||||
string='Verified for MRP',
|
||||
help="Identifies that this product has been verified "
|
||||
"to be valid for the MRP.",
|
||||
)
|
||||
mrp_lead_time = fields.Float(
|
||||
string='Lead Time',
|
||||
related='product_id.produce_delay',
|
||||
)
|
||||
main_supplier_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Main Supplier',
|
||||
compute='_compute_main_supplier', store=True,
|
||||
index=True,
|
||||
)
|
||||
main_supplierinfo_id = fields.Many2one(
|
||||
comodel_name='product.supplierinfo', string='Supplier Info',
|
||||
compute='_compute_main_supplier', store=True,
|
||||
)
|
||||
supply_method = fields.Selection(
|
||||
selection=[('buy', 'Buy'),
|
||||
('none', 'Undefined'),
|
||||
('manufacture', 'Produce'),
|
||||
('move', 'Transfer')],
|
||||
string='Supply Method',
|
||||
compute='_compute_supply_method',
|
||||
)
|
||||
|
||||
qty_available = fields.Float('Quantity Available',
|
||||
compute='_compute_qty_available')
|
||||
mrp_move_ids = fields.One2many(comodel_name='mrp.move',
|
||||
inverse_name='product_mrp_area_id',
|
||||
readonly=True,
|
||||
)
|
||||
_sql_constraints = [
|
||||
('product_mrp_area_uniq', 'unique(product_id, mrp_area_id)',
|
||||
'The product/MRP Area parameters combination must be unique.'),
|
||||
]
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
return [(area.id, '[%s] %s' % (
|
||||
area.mrp_area_id.name,
|
||||
area.product_id.display_name)) for area in self]
|
||||
|
||||
@api.multi
|
||||
def _compute_qty_available(self):
|
||||
for rec in self:
|
||||
qty_available = 0.0
|
||||
product_obj = self.env['product.product']
|
||||
# TODO: move mrp_qty_available computation, maybe unreserved??
|
||||
location_ids = self.env['stock.location'].search(
|
||||
[('id', 'child_of',
|
||||
rec.mrp_area_id.location_id.id)])
|
||||
for location in location_ids:
|
||||
product_l = product_obj.with_context(
|
||||
{'location': location.id}).browse(rec.product_id.id)
|
||||
qty_available += product_l.qty_available
|
||||
rec.qty_available = qty_available
|
||||
|
||||
@api.multi
|
||||
def _compute_supply_method(self):
|
||||
group_obj = self.env['procurement.group']
|
||||
for rec in self:
|
||||
values = {
|
||||
'warehouse_id': rec.mrp_area_id.warehouse_id,
|
||||
'company_id': self.env.user.company_id.id,
|
||||
# TODO: better way to get company
|
||||
}
|
||||
rule = group_obj._get_rule(
|
||||
rec.product_id, rec.mrp_area_id.location_id, values)
|
||||
rec.supply_method = rule.action if rule else 'none'
|
||||
|
||||
@api.multi
|
||||
@api.depends('supply_method')
|
||||
def _compute_main_supplier(self):
|
||||
"""Simplified and similar to procurement.rule logic."""
|
||||
for rec in self.filtered(lambda r: r.supply_method == 'buy'):
|
||||
suppliers = rec.product_id.seller_ids.filtered(
|
||||
lambda r: (not r.product_id or r.product_id == rec.product_id))
|
||||
if not suppliers:
|
||||
continue
|
||||
rec.main_supplierinfo_id = suppliers[0]
|
||||
rec.main_supplier_id = suppliers[0].name
|
||||
|
||||
@api.multi
|
||||
def _adjust_qty_to_order(self, qty_to_order):
|
||||
self.ensure_one()
|
||||
if (not self.mrp_maximum_order_qty and not
|
||||
self.mrp_minimum_order_qty and self.mrp_qty_multiple == 1.0):
|
||||
return qty_to_order
|
||||
if qty_to_order < self.mrp_minimum_order_qty:
|
||||
return self.mrp_minimum_order_qty
|
||||
if self.mrp_qty_multiple:
|
||||
multiplier = ceil(qty_to_order / self.mrp_qty_multiple)
|
||||
qty_to_order = multiplier * self.mrp_qty_multiple
|
||||
if self.mrp_maximum_order_qty and qty_to_order > \
|
||||
self.mrp_maximum_order_qty:
|
||||
return self.mrp_maximum_order_qty
|
||||
return qty_to_order
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright 2016-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
@@ -15,36 +15,37 @@ class Product(models.Model):
|
||||
string='Manufacturing Orders',
|
||||
domain=[('state', '=', 'draft')],
|
||||
)
|
||||
# TODO: applicable and exclude... redundant??
|
||||
mrp_applicable = fields.Boolean(string='MRP Applicable')
|
||||
mrp_exclude = fields.Boolean(string='Exclude from MRP')
|
||||
mrp_inspection_delay = fields.Integer(string='Inspection Delay')
|
||||
mrp_maximum_order_qty = fields.Float(
|
||||
string='Maximum Order Qty', default=0.0,
|
||||
)
|
||||
mrp_minimum_order_qty = fields.Float(
|
||||
string='Minimum Order Qty', default=0.0,
|
||||
)
|
||||
mrp_minimum_stock = fields.Float(string='Minimum Stock')
|
||||
mrp_nbr_days = fields.Integer(
|
||||
string='Nbr. Days', default=0,
|
||||
help="Number of days to group demand for this product during the "
|
||||
"MRP run, in order to determine the quantity to order.",
|
||||
)
|
||||
mrp_product_ids = fields.One2many(
|
||||
comodel_name='mrp.product',
|
||||
inverse_name='product_id',
|
||||
string='MRP Product data',
|
||||
)
|
||||
mrp_qty_multiple = fields.Float(string='Qty Multiple', default=1.00)
|
||||
mrp_transit_delay = fields.Integer(string='Transit Delay', default=0)
|
||||
mrp_verified = fields.Boolean(
|
||||
string='Verified for MRP',
|
||||
help="Identifies that this product has been verified "
|
||||
"to be valid for the MRP.",
|
||||
)
|
||||
purchase_order_line_ids = fields.One2many(
|
||||
comodel_name='purchase.order.line',
|
||||
inverse_name='product_id',
|
||||
string='Purchase Orders',
|
||||
)
|
||||
mrp_area_ids = fields.One2many(
|
||||
comodel_name='product.mrp.area',
|
||||
inverse_name='product_id',
|
||||
string='MRP Area parameters'
|
||||
)
|
||||
mrp_area_count = fields.Integer(
|
||||
string='MRP Area Parameter Count',
|
||||
readonly=True,
|
||||
compute='_compute_mrp_area_count')
|
||||
|
||||
@api.multi
|
||||
def _compute_mrp_area_count(self):
|
||||
for rec in self:
|
||||
rec.mrp_area_count = len(rec.mrp_area_ids)
|
||||
|
||||
@api.multi
|
||||
def action_view_mrp_area_parameters(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
product_ids = self.ids
|
||||
if len(product_ids) > 1:
|
||||
result['domain'] = [('product_id', 'in', product_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = product_ids[0]
|
||||
result['context'] = {'default_product_id': product_ids[0]}
|
||||
return result
|
||||
|
||||
@@ -7,222 +7,34 @@ 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.",
|
||||
mrp_area_ids = fields.One2many(
|
||||
comodel_name='product.mrp.area',
|
||||
inverse_name='product_tmpl_id',
|
||||
string='MRP Area parameters',
|
||||
)
|
||||
mrp_area_count = fields.Integer(
|
||||
string='MRP Area Parameter Count',
|
||||
readonly=True,
|
||||
compute='_compute_mrp_area_count')
|
||||
|
||||
@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.multi
|
||||
def _compute_mrp_area_count(self):
|
||||
for rec in self:
|
||||
rec.mrp_area_count = len(rec.mrp_area_ids)
|
||||
|
||||
@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
|
||||
@api.multi
|
||||
def action_view_mrp_area_parameters(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
mrp_area_ids = self.with_context(
|
||||
active_test=False).mrp_area_ids.ids
|
||||
if len(mrp_area_ids) > 1:
|
||||
result['domain'] = [('id', 'in', mrp_area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = mrp_area_ids[0]
|
||||
result['context'] = {
|
||||
'default_product_id': self.product_variant_ids[0].id}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user