[IMP] mrp_multi_level: black, isort

This commit is contained in:
Lois Rilo
2019-12-17 15:09:48 +01:00
parent 9ed03440aa
commit 1df4ba9c0b
14 changed files with 1193 additions and 1048 deletions

View File

@@ -8,32 +8,29 @@ from odoo import api, fields, models
class MrpArea(models.Model):
_name = 'mrp.area'
_name = "mrp.area"
_description = "MRP Area"
name = fields.Char(required=True)
warehouse_id = fields.Many2one(
comodel_name='stock.warehouse', string='Warehouse',
required=True,
comodel_name="stock.warehouse", string="Warehouse", required=True
)
company_id = fields.Many2one(
comodel_name='res.company',
related='warehouse_id.company_id',
store=True,
comodel_name="res.company", related="warehouse_id.company_id", store=True
)
location_id = fields.Many2one(
comodel_name='stock.location', string='Location',
required=True,
comodel_name="stock.location", string="Location", required=True
)
active = fields.Boolean(default=True)
calendar_id = fields.Many2one(
comodel_name='resource.calendar',
string='Working Hours',
related='warehouse_id.calendar_id',
comodel_name="resource.calendar",
string="Working Hours",
related="warehouse_id.calendar_id",
)
@api.multi
def _get_locations(self):
self.ensure_one()
return self.env['stock.location'].search([
('id', 'child_of', self.location_id.id)])
return self.env["stock.location"].search(
[("id", "child_of", self.location_id.id)]
)

View File

@@ -4,68 +4,63 @@
# - Lois Rilo Antelo <lois.rilo@eficent.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
from datetime import date, timedelta
from datetime import timedelta, date
from odoo import api, fields, models
class MrpInventory(models.Model):
_name = 'mrp.inventory'
_order = 'product_mrp_area_id, date'
_description = 'MRP inventory projections'
_rec_name = 'product_mrp_area_id'
_name = "mrp.inventory"
_order = "product_mrp_area_id, date"
_description = "MRP inventory projections"
_rec_name = "product_mrp_area_id"
# TODO: name to pass to procurements?
# TODO: compute procurement_date to pass to the wizard? not needed for
# PO at least. Check for MO and moves
mrp_area_id = fields.Many2one(
comodel_name='mrp.area', string='MRP Area',
related='product_mrp_area_id.mrp_area_id', store=True,
comodel_name="mrp.area",
string="MRP Area",
related="product_mrp_area_id.mrp_area_id",
store=True,
)
product_mrp_area_id = fields.Many2one(
comodel_name='product.mrp.area', string='Product Parameters',
comodel_name="product.mrp.area",
string="Product Parameters",
index=True,
required=True,
)
company_id = fields.Many2one(
comodel_name='res.company',
related='product_mrp_area_id.mrp_area_id.warehouse_id.company_id',
comodel_name="res.company",
related="product_mrp_area_id.mrp_area_id.warehouse_id.company_id",
store=True,
)
product_id = fields.Many2one(
comodel_name='product.product',
related='product_mrp_area_id.product_id',
comodel_name="product.product",
related="product_mrp_area_id.product_id",
store=True,
)
uom_id = fields.Many2one(
comodel_name='uom.uom', string='Product UoM',
compute='_compute_uom_id',
comodel_name="uom.uom", string="Product UoM", compute="_compute_uom_id"
)
date = fields.Date(string='Date')
demand_qty = fields.Float(string='Demand')
supply_qty = fields.Float(string='Supply')
initial_on_hand_qty = fields.Float(string='Starting Inventory')
final_on_hand_qty = fields.Float(string='Forecasted Inventory')
date = fields.Date(string="Date")
demand_qty = fields.Float(string="Demand")
supply_qty = fields.Float(string="Supply")
initial_on_hand_qty = fields.Float(string="Starting Inventory")
final_on_hand_qty = fields.Float(string="Forecasted Inventory")
to_procure = fields.Float(
string="To procure",
compute="_compute_to_procure",
store=True,
string="To procure", compute="_compute_to_procure", store=True
)
running_availability = fields.Float(
string="Planned Availability",
help="Theoretical inventory level if all planned orders"
"were released.",
help="Theoretical inventory level if all planned orders" "were released.",
)
order_release_date = fields.Date(
string="Order Release Date",
compute="_compute_order_release_date",
store=True,
string="Order Release Date", compute="_compute_order_release_date", store=True
)
planned_order_ids = fields.One2many(
comodel_name="mrp.planned.order",
inverse_name="mrp_inventory_id",
readonly=True,
comodel_name="mrp.planned.order", inverse_name="mrp_inventory_id", readonly=True
)
@api.multi
@@ -76,14 +71,17 @@ class MrpInventory(models.Model):
@api.depends("planned_order_ids", "planned_order_ids.qty_released")
def _compute_to_procure(self):
for rec in self:
rec.to_procure = sum(rec.planned_order_ids.mapped('mrp_qty')) - \
sum(rec.planned_order_ids.mapped('qty_released'))
rec.to_procure = sum(rec.planned_order_ids.mapped("mrp_qty")) - sum(
rec.planned_order_ids.mapped("qty_released")
)
@api.multi
@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')
@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):
@@ -93,10 +91,12 @@ class MrpInventory(models.Model):
# dt_date is at the beginning of the day (00:00),
# so we can subtract the delay straight forward.
order_release_date = rec.mrp_area_id.calendar_id.plan_days(
-delay, dt_date).date()
-delay, dt_date
).date()
else:
order_release_date = fields.Date.from_string(
rec.date) - timedelta(days=delay)
order_release_date = fields.Date.from_string(rec.date) - timedelta(
days=delay
)
if order_release_date < today:
order_release_date = today
rec.order_release_date = order_release_date

View File

@@ -2,13 +2,13 @@
# © 2016-18 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models, fields
from odoo import fields, models
class MrpMove(models.Model):
_name = 'mrp.move'
_name = "mrp.move"
_description = "MRP Move"
_order = 'product_mrp_area_id, mrp_date, mrp_type desc, id'
_order = "product_mrp_area_id, mrp_date, mrp_type desc, id"
# TODO: too many indexes...
@@ -26,19 +26,19 @@ class MrpMove(models.Model):
index=True,
)
company_id = fields.Many2one(
comodel_name='res.company',
related='product_mrp_area_id.mrp_area_id.warehouse_id.company_id',
comodel_name="res.company",
related="product_mrp_area_id.mrp_area_id.warehouse_id.company_id",
store=True,
)
product_id = fields.Many2one(
comodel_name='product.product',
related='product_mrp_area_id.product_id',
comodel_name="product.product",
related="product_mrp_area_id.product_id",
store=True,
)
current_date = fields.Date(string='Current Date')
current_qty = fields.Float(string='Current Qty')
mrp_date = fields.Date(string='MRP Date')
current_date = fields.Date(string="Current Date")
current_qty = fields.Float(string="Current Qty")
mrp_date = fields.Date(string="MRP Date")
planned_order_up_ids = fields.Many2many(
comodel_name="mrp.planned.order",
relation="mrp_move_planned_order_rel",
@@ -46,49 +46,48 @@ class MrpMove(models.Model):
column2="order_id",
string="Planned Orders UP",
)
mrp_order_number = fields.Char(string='Order Number')
mrp_order_number = fields.Char(string="Order Number")
mrp_origin = fields.Selection(
selection=[('mo', 'Manufacturing Order'),
('po', 'Purchase Order'),
('mv', 'Move'),
('fc', 'Forecast'),
('mrp', 'MRP')],
string='Origin')
mrp_qty = fields.Float(string='MRP Quantity')
mrp_type = fields.Selection(
selection=[('s', 'Supply'), ('d', 'Demand')],
string='Type',
selection=[
("mo", "Manufacturing Order"),
("po", "Purchase Order"),
("mv", "Move"),
("fc", "Forecast"),
("mrp", "MRP"),
],
string="Origin",
)
name = fields.Char(string='Description')
mrp_qty = fields.Float(string="MRP Quantity")
mrp_type = fields.Selection(
selection=[("s", "Supply"), ("d", "Demand")], string="Type"
)
name = fields.Char(string="Description")
parent_product_id = fields.Many2one(
comodel_name="product.product",
string="Parent Product", index=True,
comodel_name="product.product", string="Parent Product", index=True
)
production_id = fields.Many2one(
comodel_name='mrp.production',
string='Manufacturing Order', index=True,
comodel_name="mrp.production", string="Manufacturing Order", index=True
)
purchase_line_id = fields.Many2one(
comodel_name='purchase.order.line',
string='Purchase Order Line', index=True,
comodel_name="purchase.order.line", string="Purchase Order Line", index=True
)
purchase_order_id = fields.Many2one(
comodel_name='purchase.order',
string='Purchase Order', index=True,
comodel_name="purchase.order", string="Purchase Order", index=True
)
state = fields.Selection(
selection=[('draft', 'Draft'),
('assigned', 'Assigned'),
('confirmed', 'Confirmed'),
('waiting', 'Waiting'),
('partially_available', 'Partially Available'),
('ready', 'Ready'),
('sent', 'Sent'),
('to approve', 'To Approve'),
('approved', 'Approved')],
string='State',
selection=[
("draft", "Draft"),
("assigned", "Assigned"),
("confirmed", "Confirmed"),
("waiting", "Waiting"),
("partially_available", "Partially Available"),
("ready", "Ready"),
("sent", "Sent"),
("to approve", "To Approve"),
("approved", "Approved"),
],
string="State",
)
stock_move_id = fields.Many2one(
comodel_name='stock.move',
string='Stock Move', index=True,
comodel_name="stock.move", string="Stock Move", index=True
)

View File

@@ -2,7 +2,7 @@
# - Lois Rilo Antelo <lois.rilo@eficent.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models, fields
from odoo import fields, models
class MrpPlannedOrder(models.Model):
@@ -26,8 +26,8 @@ class MrpPlannedOrder(models.Model):
readonly=True,
)
company_id = fields.Many2one(
comodel_name='res.company',
related='product_mrp_area_id.mrp_area_id.warehouse_id.company_id',
comodel_name="res.company",
related="product_mrp_area_id.mrp_area_id.warehouse_id.company_id",
store=True,
)
product_id = fields.Many2one(
@@ -37,12 +37,10 @@ class MrpPlannedOrder(models.Model):
readonly=True,
)
order_release_date = fields.Date(
string="Release Date",
help="Order release date planned by MRP.",
string="Release Date", help="Order release date planned by MRP."
)
due_date = fields.Date(
string="Due Date",
help="Date in which the supply must have been completed.",
string="Due Date", help="Date in which the supply must have been completed."
)
qty_released = fields.Float()
fixed = fields.Boolean()
@@ -55,12 +53,14 @@ class MrpPlannedOrder(models.Model):
string="MRP Move DOWN",
)
mrp_action = fields.Selection(
selection=[("manufacture", "Manufacturing Order"),
("buy", "Purchase Order"),
('pull', 'Pull From'),
('push', 'Push To'),
('pull_push', 'Pull & Push'),
("none", "None")],
selection=[
("manufacture", "Manufacturing Order"),
("buy", "Purchase Order"),
("pull", "Pull From"),
("push", "Push To"),
("pull_push", "Pull & Push"),
("none", "None"),
],
string="Action",
)
mrp_inventory_id = fields.Many2one(

View File

@@ -6,99 +6,89 @@
from math import ceil
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ProductMRPArea(models.Model):
_name = 'product.mrp.area'
_description = 'Product MRP Area'
_name = "product.mrp.area"
_description = "Product MRP Area"
active = fields.Boolean(default=True)
mrp_area_id = fields.Many2one(
comodel_name='mrp.area',
required=True,
)
mrp_area_id = fields.Many2one(comodel_name="mrp.area", required=True)
company_id = fields.Many2one(
comodel_name='res.company',
related='mrp_area_id.warehouse_id.company_id',
comodel_name="res.company",
related="mrp_area_id.warehouse_id.company_id",
store=True,
)
product_id = fields.Many2one(
comodel_name='product.product',
required=True,
string='Product',
comodel_name="product.product", required=True, string="Product"
)
product_tmpl_id = fields.Many2one(
comodel_name='product.template',
comodel_name="product.template",
readonly=True,
related='product_id.product_tmpl_id',
related="product_id.product_tmpl_id",
store=True,
)
location_id = fields.Many2one(
related="mrp_area_id.location_id",
)
location_id = fields.Many2one(related="mrp_area_id.location_id")
location_proc_id = fields.Many2one(
string="Procure Location",
comodel_name="stock.location",
domain="[('location_id', 'child_of', location_id)]",
help="Set this if you need to procure from a different location"
"than area's location.",
"than area's location.",
)
# 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_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="Safety Stock")
mrp_nbr_days = fields.Integer(
string='Nbr. Days', default=0,
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 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_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',
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',
compute='_compute_mrp_lead_time',
"to be valid for the MRP.",
)
mrp_lead_time = fields.Float(string="Lead Time", compute="_compute_mrp_lead_time")
main_supplier_id = fields.Many2one(
comodel_name='res.partner', string='Main Supplier',
compute='_compute_main_supplier', store=True,
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,
comodel_name="product.supplierinfo",
string="Supplier Info",
compute="_compute_main_supplier",
store=True,
)
supply_method = fields.Selection(
selection=[('buy', 'Buy'),
('none', 'Undefined'),
('manufacture', 'Produce'),
('pull', 'Pull From'),
('push', 'Push To'),
('pull_push', 'Pull & Push')],
string='Supply Method',
compute='_compute_supply_method',
selection=[
("buy", "Buy"),
("none", "Undefined"),
("manufacture", "Produce"),
("pull", "Pull From"),
("push", "Push To"),
("pull_push", "Pull & Push"),
],
string="Supply Method",
compute="_compute_supply_method",
)
qty_available = fields.Float(
string="Quantity Available",
compute="_compute_qty_available",
string="Quantity Available", compute="_compute_qty_available"
)
mrp_move_ids = fields.One2many(
comodel_name='mrp.move',
inverse_name='product_mrp_area_id',
readonly=True,
comodel_name="mrp.move", inverse_name="product_mrp_area_id", readonly=True
)
planned_order_ids = fields.One2many(
comodel_name="mrp.planned.order",
@@ -107,29 +97,41 @@ class ProductMRPArea(models.Model):
)
_sql_constraints = [
('product_mrp_area_uniq', 'unique(product_id, mrp_area_id)',
'The product/MRP Area parameters combination must be unique.'),
(
"product_mrp_area_uniq",
"unique(product_id, mrp_area_id)",
"The product/MRP Area parameters combination must be unique.",
)
]
@api.multi
@api.constrains(
"mrp_minimum_order_qty", "mrp_maximum_order_qty", "mrp_qty_multiple",
"mrp_minimum_stock", "mrp_nbr_days",
"mrp_minimum_order_qty",
"mrp_maximum_order_qty",
"mrp_qty_multiple",
"mrp_minimum_stock",
"mrp_nbr_days",
)
def _check_negatives(self):
values = self.read([
"mrp_minimum_order_qty", "mrp_maximum_order_qty",
"mrp_qty_multiple", "mrp_minimum_stock", "mrp_nbr_days",
])
values = self.read(
[
"mrp_minimum_order_qty",
"mrp_maximum_order_qty",
"mrp_qty_multiple",
"mrp_minimum_stock",
"mrp_nbr_days",
]
)
for rec in values:
if any(v < 0 for v in rec.values()):
raise ValidationError(_("You cannot use a negative number."))
@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]
return [
(area.id, "[{}] {}".format(area.mrp_area_id.name, area.product_id.display_name))
for area in self
]
@api.multi
def _compute_mrp_lead_time(self):
@@ -140,36 +142,37 @@ class ProductMRPArea(models.Model):
for rec in purchased:
rec.mrp_lead_time = rec.main_supplierinfo_id.delay
# TODO: 'move' supply method.
for rec in (self - produced - purchased):
for rec in self - produced - purchased:
rec.mrp_lead_time = 0
@api.multi
def _compute_qty_available(self):
for rec in self:
rec.qty_available = rec.product_id.with_context(
{'location': rec.mrp_area_id.location_id.id}).qty_available
{"location": rec.mrp_area_id.location_id.id}
).qty_available
@api.multi
def _compute_supply_method(self):
group_obj = self.env['procurement.group']
group_obj = self.env["procurement.group"]
for rec in self:
proc_loc = rec.location_proc_id or rec.mrp_area_id.location_id
values = {
'warehouse_id': rec.mrp_area_id.warehouse_id,
'company_id': self.env.user.company_id.id,
"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, proc_loc, values)
rec.supply_method = rule.action if rule else 'none'
rec.supply_method = rule.action if rule else "none"
@api.multi
@api.depends('supply_method', 'product_id.route_ids',
'product_id.seller_ids')
@api.depends("supply_method", "product_id.route_ids", "product_id.seller_ids")
def _compute_main_supplier(self):
"""Simplified and similar to procurement.rule logic."""
for rec in self.filtered(lambda r: r.supply_method == 'buy'):
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))
lambda r: (not r.product_id or r.product_id == rec.product_id)
)
if not suppliers:
continue
rec.main_supplierinfo_id = suppliers[0]
@@ -178,15 +181,17 @@ class ProductMRPArea(models.Model):
@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):
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:
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

View File

@@ -2,33 +2,34 @@
# Copyright 2016-18 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import ast
from odoo import api, fields, models
class Product(models.Model):
_inherit = 'product.product'
_inherit = "product.product"
llc = fields.Integer(string='Low Level Code', default=0)
llc = fields.Integer(string="Low Level Code", default=0)
manufacturing_order_ids = fields.One2many(
comodel_name='mrp.production',
inverse_name='product_id',
string='Manufacturing Orders',
domain=[('state', '=', 'draft')],
comodel_name="mrp.production",
inverse_name="product_id",
string="Manufacturing Orders",
domain=[("state", "=", "draft")],
)
purchase_order_line_ids = fields.One2many(
comodel_name='purchase.order.line',
inverse_name='product_id',
string='Purchase Orders',
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'
comodel_name="product.mrp.area",
inverse_name="product_id",
string="MRP Area parameters",
)
mrp_area_count = fields.Integer(
string='MRP Area Parameter Count',
string="MRP Area Parameter Count",
readonly=True,
compute='_compute_mrp_area_count',
compute="_compute_mrp_area_count",
)
@api.multi
@@ -39,21 +40,21 @@ class Product(models.Model):
@api.multi
def action_view_mrp_area_parameters(self):
self.ensure_one()
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
action = self.env.ref("mrp_multi_level.product_mrp_area_action")
result = action.read()[0]
ctx = ast.literal_eval(result.get('context'))
ctx = ast.literal_eval(result.get("context"))
if not ctx:
ctx = {}
mrp_areas = self.env['mrp.area'].search([])
mrp_areas = self.env["mrp.area"].search([])
if len(mrp_areas) == 1:
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
ctx.update({"default_mrp_area_id": mrp_areas[0].id})
area_ids = self.mrp_area_ids.ids
ctx.update({'default_product_id': self.id})
ctx.update({"default_product_id": self.id})
if self.mrp_area_count != 1:
result['domain'] = [('id', 'in', area_ids)]
result["domain"] = [("id", "in", 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'] = area_ids[0]
result['context'] = ctx
res = self.env.ref("mrp_multi_level.product_mrp_area_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = area_ids[0]
result["context"] = ctx
return result

View File

@@ -1,21 +1,22 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import ast
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"
mrp_area_ids = fields.One2many(
comodel_name='product.mrp.area',
inverse_name='product_tmpl_id',
string='MRP Area parameters',
comodel_name="product.mrp.area",
inverse_name="product_tmpl_id",
string="MRP Area parameters",
)
mrp_area_count = fields.Integer(
string='MRP Area Parameter Count',
string="MRP Area Parameter Count",
readonly=True,
compute='_compute_mrp_area_count',
compute="_compute_mrp_area_count",
)
@api.multi
@@ -26,24 +27,23 @@ class ProductTemplate(models.Model):
@api.multi
def action_view_mrp_area_parameters(self):
self.ensure_one()
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
action = self.env.ref("mrp_multi_level.product_mrp_area_action")
result = action.read()[0]
ctx = ast.literal_eval(result.get('context'))
mrp_areas = self.env['mrp.area'].search([])
if 'context' not in result:
result['context'] = {}
ctx = ast.literal_eval(result.get("context"))
mrp_areas = self.env["mrp.area"].search([])
if "context" not in result:
result["context"] = {}
if len(mrp_areas) == 1:
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
mrp_area_ids = self.with_context(
active_test=False).mrp_area_ids.ids
ctx.update({"default_mrp_area_id": mrp_areas[0].id})
mrp_area_ids = self.with_context(active_test=False).mrp_area_ids.ids
if len(self.product_variant_ids) == 1:
variant = self.product_variant_ids[0]
ctx.update({'default_product_id': variant.id})
ctx.update({"default_product_id": variant.id})
if len(mrp_area_ids) != 1:
result['domain'] = [('id', 'in', mrp_area_ids)]
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'] = ctx
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"] = ctx
return result

View File

@@ -7,10 +7,11 @@ from odoo import fields, models
class StockLocation(models.Model):
_inherit = 'stock.location'
_inherit = "stock.location"
mrp_area_id = fields.Many2one(
comodel_name='mrp.area', string='MRP Area',
comodel_name="mrp.area",
string="MRP Area",
help="Requirements for a particular MRP area are combined for the "
"purposes of procurement by the MRP.",
"purposes of procurement by the MRP.",
)