mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_multi_level: enchance traceability with origin.
* keept description of planned orders verbose. * make it translatable in most cases. * while grouping demand include the product in the description. * add `origin` field not mrp moves and planned orders. Fill it with top level demand origin.
This commit is contained in:
@@ -63,6 +63,7 @@ class MrpMove(models.Model):
|
|||||||
selection=[("s", "Supply"), ("d", "Demand")], string="Type"
|
selection=[("s", "Supply"), ("d", "Demand")], string="Type"
|
||||||
)
|
)
|
||||||
name = fields.Char(string="Description")
|
name = fields.Char(string="Description")
|
||||||
|
origin = fields.Char(string="Source Document")
|
||||||
parent_product_id = fields.Many2one(
|
parent_product_id = fields.Many2one(
|
||||||
comodel_name="product.product", string="Parent Product", index=True
|
comodel_name="product.product", string="Parent Product", index=True
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class MrpPlannedOrder(models.Model):
|
|||||||
_order = "due_date, id"
|
_order = "due_date, id"
|
||||||
|
|
||||||
name = fields.Char(string="Description")
|
name = fields.Char(string="Description")
|
||||||
|
origin = fields.Char(string="Source Document")
|
||||||
product_mrp_area_id = fields.Many2one(
|
product_mrp_area_id = fields.Many2one(
|
||||||
comodel_name="product.mrp.area",
|
comodel_name="product.mrp.area",
|
||||||
string="Product MRP Area",
|
string="Product MRP Area",
|
||||||
|
|||||||
71
mrp_multi_level/views/mrp_move_views.xml
Normal file
71
mrp_multi_level/views/mrp_move_views.xml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="mrp_move_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">mrp.move.form</field>
|
||||||
|
<field name="model">mrp.move</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
<group>
|
||||||
|
<field name="mrp_area_id" />
|
||||||
|
<field
|
||||||
|
name="company_id"
|
||||||
|
groups="base.group_multi_company"
|
||||||
|
/>
|
||||||
|
<field name="product_id" />
|
||||||
|
<field name="product_mrp_area_id" />
|
||||||
|
<field name="mrp_origin" />
|
||||||
|
<field
|
||||||
|
name="production_id"
|
||||||
|
attrs="{'invisible':[('mrp_origin', '!=', 'mo')]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="purchase_order_id"
|
||||||
|
attrs="{'invisible':[('mrp_origin', '!=', 'po')]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="purchase_line_id"
|
||||||
|
attrs="{'invisible':[('mrp_origin', '!=', 'po')]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="stock_move_id"
|
||||||
|
attrs="{'invisible':[('mrp_origin', '!=', 'mv')]}"
|
||||||
|
/>
|
||||||
|
<field name="name" />
|
||||||
|
<field name="origin" />
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="mrp_date" />
|
||||||
|
<field
|
||||||
|
name="current_date"
|
||||||
|
attrs="{'invisible': [('current_date', '=', False)]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="state"
|
||||||
|
attrs="{'invisible': [('state', '=', False)]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="mrp_order_number"
|
||||||
|
attrs="{'invisible': [('mrp_order_number', '=', False)]}"
|
||||||
|
/>
|
||||||
|
<field
|
||||||
|
name="parent_product_id"
|
||||||
|
attrs="{'invisible': [('parent_product_id', '=', False)]}"
|
||||||
|
/>
|
||||||
|
<field name="mrp_qty" />
|
||||||
|
<field name="current_qty" />
|
||||||
|
<field name="mrp_type" />
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<notebook>
|
||||||
|
<page string="Planned Orders UP" name="planned_orders_up">
|
||||||
|
<field name="planned_order_up_ids" readonly="1" />
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree decoration-info="fixed != True">
|
<tree decoration-info="fixed != True">
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="origin" />
|
||||||
<field name="product_mrp_area_id" />
|
<field name="product_mrp_area_id" />
|
||||||
<field name="product_id" />
|
<field name="product_id" />
|
||||||
<field name="mrp_area_id" />
|
<field name="mrp_area_id" />
|
||||||
@@ -76,6 +77,7 @@
|
|||||||
<field name="model">mrp.planned.order</field>
|
<field name="model">mrp.planned.order</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search>
|
<search>
|
||||||
|
<field name="origin" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="product_id" />
|
<field name="product_id" />
|
||||||
<field name="mrp_area_id" />
|
<field name="mrp_area_id" />
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class MrpInventoryProcure(models.TransientModel):
|
|||||||
item.uom_id,
|
item.uom_id,
|
||||||
item.location_id,
|
item.location_id,
|
||||||
"MRP: " + item.planned_order_id.name or str(self.env.user.login),
|
"MRP: " + item.planned_order_id.name or str(self.env.user.login),
|
||||||
"MRP: " + item.planned_order_id.name or str(self.env.user.login),
|
"MRP: " + item.planned_order_id.origin or str(self.env.user.login),
|
||||||
item.mrp_inventory_id.company_id,
|
item.mrp_inventory_id.company_id,
|
||||||
values,
|
values,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -99,12 +99,13 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
"mrp_order_number": order_number,
|
"mrp_order_number": order_number,
|
||||||
"parent_product_id": parent_product_id,
|
"parent_product_id": parent_product_id,
|
||||||
"name": order_number,
|
"name": order_number,
|
||||||
|
"origin": order_number,
|
||||||
"state": move.state,
|
"state": move.state,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_planned_order_data(
|
def _prepare_planned_order_data(
|
||||||
self, product_mrp_area, qty, mrp_date_supply, mrp_action_date, name
|
self, product_mrp_area, qty, mrp_date_supply, mrp_action_date, name, values
|
||||||
):
|
):
|
||||||
return {
|
return {
|
||||||
"product_mrp_area_id": product_mrp_area.id,
|
"product_mrp_area_id": product_mrp_area.id,
|
||||||
@@ -113,13 +114,14 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
"order_release_date": mrp_action_date,
|
"order_release_date": mrp_action_date,
|
||||||
"mrp_action": product_mrp_area.supply_method,
|
"mrp_action": product_mrp_area.supply_method,
|
||||||
"qty_released": 0.0,
|
"qty_released": 0.0,
|
||||||
"name": name,
|
"name": "Planned supply for: " + name,
|
||||||
|
"origin": values.get("origin") or name,
|
||||||
"fixed": False,
|
"fixed": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_mrp_move_data_bom_explosion(
|
def _prepare_mrp_move_data_bom_explosion(
|
||||||
self, product, bomline, qty, mrp_date_demand_2, bom, name
|
self, product, bomline, qty, mrp_date_demand_2, bom, name, planned_order
|
||||||
):
|
):
|
||||||
product_mrp_area = self._get_product_mrp_area_from_product_and_area(
|
product_mrp_area = self._get_product_mrp_area_from_product_and_area(
|
||||||
bomline.product_id, product.mrp_area_id
|
bomline.product_id, product.mrp_area_id
|
||||||
@@ -149,7 +151,13 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
"mrp_origin": "mrp",
|
"mrp_origin": "mrp",
|
||||||
"mrp_order_number": None,
|
"mrp_order_number": None,
|
||||||
"parent_product_id": bom.product_id.id,
|
"parent_product_id": bom.product_id.id,
|
||||||
"name": name or product.product_id.default_code or product.product_id.name,
|
"name": (
|
||||||
|
"Demand Bom Explosion: %s"
|
||||||
|
% (name or product.product_id.default_code or product.product_id.name)
|
||||||
|
).replace(
|
||||||
|
"Demand Bom Explosion: Demand Bom Explosion: ", "Demand Bom Explosion: "
|
||||||
|
),
|
||||||
|
"origin": planned_order.origin,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -206,7 +214,13 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
move_data = self._prepare_mrp_move_data_bom_explosion(
|
move_data = self._prepare_mrp_move_data_bom_explosion(
|
||||||
product_mrp_area_id, bomline, qty, mrp_date_demand_2, bom, name
|
product_mrp_area_id,
|
||||||
|
bomline,
|
||||||
|
qty,
|
||||||
|
mrp_date_demand_2,
|
||||||
|
bom,
|
||||||
|
name,
|
||||||
|
action,
|
||||||
)
|
)
|
||||||
mrpmove_id2 = self.env["mrp.move"].create(move_data)
|
mrpmove_id2 = self.env["mrp.move"].create(move_data)
|
||||||
if hasattr(action, "mrp_move_down_ids"):
|
if hasattr(action, "mrp_move_down_ids"):
|
||||||
@@ -249,7 +263,7 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
qty = product_mrp_area_id._adjust_qty_to_order(qty_to_order)
|
qty = product_mrp_area_id._adjust_qty_to_order(qty_to_order)
|
||||||
qty_to_order -= qty
|
qty_to_order -= qty
|
||||||
order_data = self._prepare_planned_order_data(
|
order_data = self._prepare_planned_order_data(
|
||||||
product_mrp_area_id, qty, mrp_date_supply, mrp_action_date, name
|
product_mrp_area_id, qty, mrp_date_supply, mrp_action_date, name, values
|
||||||
)
|
)
|
||||||
planned_order = self.env["mrp.planned.order"].create(order_data)
|
planned_order = self.env["mrp.planned.order"].create(order_data)
|
||||||
qty_ordered = qty_ordered + qty
|
qty_ordered = qty_ordered + qty
|
||||||
@@ -493,19 +507,27 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
or (onhand + last_qty) < product_mrp_area.mrp_minimum_stock
|
or (onhand + last_qty) < product_mrp_area.mrp_minimum_stock
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
name = ",".join(demand_origin)
|
name = _(
|
||||||
|
"Grouped Demand of %(product_name)s for %(delta_days)d Days"
|
||||||
|
) % dict(
|
||||||
|
product_name=product_mrp_area.product_id.display_name,
|
||||||
|
delta_days=grouping_delta,
|
||||||
|
)
|
||||||
|
origin = ",".join(list(set(demand_origin)))
|
||||||
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
|
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
|
||||||
cm = self.create_action(
|
cm = self.create_action(
|
||||||
product_mrp_area_id=product_mrp_area,
|
product_mrp_area_id=product_mrp_area,
|
||||||
mrp_date=last_date,
|
mrp_date=last_date,
|
||||||
mrp_qty=qtytoorder,
|
mrp_qty=qtytoorder,
|
||||||
name=name,
|
name=name,
|
||||||
|
values=dict(origin=origin),
|
||||||
)
|
)
|
||||||
qty_ordered = cm.get("qty_ordered", 0.0)
|
qty_ordered = cm.get("qty_ordered", 0.0)
|
||||||
onhand = onhand + last_qty + qty_ordered
|
onhand = onhand + last_qty + qty_ordered
|
||||||
last_date = None
|
last_date = None
|
||||||
last_qty = 0.00
|
last_qty = 0.00
|
||||||
nbr_create += 1
|
nbr_create += 1
|
||||||
|
demand_origin = []
|
||||||
if (
|
if (
|
||||||
onhand + last_qty + move.mrp_qty
|
onhand + last_qty + move.mrp_qty
|
||||||
) < product_mrp_area.mrp_minimum_stock or (
|
) < product_mrp_area.mrp_minimum_stock or (
|
||||||
@@ -519,16 +541,23 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
last_date = fields.Date.from_string(move.mrp_date)
|
last_date = fields.Date.from_string(move.mrp_date)
|
||||||
onhand += move.mrp_qty
|
onhand += move.mrp_qty
|
||||||
demand_origin.append(move.name)
|
demand_origin.append(move.origin or move.name)
|
||||||
|
|
||||||
if last_date and last_qty != 0.00:
|
if last_date and last_qty != 0.00:
|
||||||
name = ",".join(demand_origin)
|
name = _(
|
||||||
|
"Grouped Demand of %(product_name)s for %(delta_days)d Days"
|
||||||
|
) % dict(
|
||||||
|
product_name=product_mrp_area.product_id.display_name,
|
||||||
|
delta_days=grouping_delta,
|
||||||
|
)
|
||||||
|
origin = ",".join(list(set(demand_origin)))
|
||||||
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
|
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
|
||||||
cm = self.create_action(
|
cm = self.create_action(
|
||||||
product_mrp_area_id=product_mrp_area,
|
product_mrp_area_id=product_mrp_area,
|
||||||
mrp_date=last_date,
|
mrp_date=last_date,
|
||||||
mrp_qty=qtytoorder,
|
mrp_qty=qtytoorder,
|
||||||
name=name,
|
name=name,
|
||||||
|
values=dict(origin=origin),
|
||||||
)
|
)
|
||||||
qty_ordered = cm.get("qty_ordered", 0.0)
|
qty_ordered = cm.get("qty_ordered", 0.0)
|
||||||
onhand += qty_ordered
|
onhand += qty_ordered
|
||||||
@@ -573,6 +602,7 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
mrp_date=move.mrp_date,
|
mrp_date=move.mrp_date,
|
||||||
mrp_qty=qtytoorder,
|
mrp_qty=qtytoorder,
|
||||||
name=move.name,
|
name=move.name,
|
||||||
|
values=dict(origin=move.origin),
|
||||||
)
|
)
|
||||||
qty_ordered = cm["qty_ordered"]
|
qty_ordered = cm["qty_ordered"]
|
||||||
onhand += move.mrp_qty + qty_ordered
|
onhand += move.mrp_qty + qty_ordered
|
||||||
@@ -586,11 +616,13 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
|
|
||||||
if onhand < product_mrp_area.mrp_minimum_stock and nbr_create == 0:
|
if onhand < product_mrp_area.mrp_minimum_stock and nbr_create == 0:
|
||||||
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand
|
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand
|
||||||
|
name = _("Safety Stock")
|
||||||
cm = self.create_action(
|
cm = self.create_action(
|
||||||
product_mrp_area_id=product_mrp_area,
|
product_mrp_area_id=product_mrp_area,
|
||||||
mrp_date=date.today(),
|
mrp_date=date.today(),
|
||||||
mrp_qty=qtytoorder,
|
mrp_qty=qtytoorder,
|
||||||
name="Minimum Stock",
|
name=name,
|
||||||
|
values=dict(origin=name),
|
||||||
)
|
)
|
||||||
qty_ordered = cm["qty_ordered"]
|
qty_ordered = cm["qty_ordered"]
|
||||||
onhand += qty_ordered
|
onhand += qty_ordered
|
||||||
|
|||||||
Reference in New Issue
Block a user