mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
@@ -6,7 +6,7 @@
|
||||
|
||||
from datetime import date, timedelta
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class MrpInventory(models.Model):
|
||||
@@ -109,3 +109,18 @@ class MrpInventory(models.Model):
|
||||
if order_release_date < today:
|
||||
order_release_date = today
|
||||
rec.order_release_date = order_release_date
|
||||
|
||||
def action_open_planned_orders(self):
|
||||
planned_order_ids = []
|
||||
for rec in self:
|
||||
planned_order_ids += rec.planned_order_ids.ids
|
||||
|
||||
domain = [("id", "in", planned_order_ids)]
|
||||
|
||||
return {
|
||||
"name": _("Planned Orders"),
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "mrp.planned.order",
|
||||
"view_mode": "tree,form",
|
||||
"domain": domain,
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ class MrpMove(models.Model):
|
||||
selection=[("s", "Supply"), ("d", "Demand")], string="Type"
|
||||
)
|
||||
name = fields.Char(string="Description")
|
||||
origin = fields.Char(string="Source Document")
|
||||
parent_product_id = fields.Many2one(
|
||||
comodel_name="product.product", string="Parent Product", index=True
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ class MrpPlannedOrder(models.Model):
|
||||
_order = "due_date, id"
|
||||
|
||||
name = fields.Char(string="Description")
|
||||
origin = fields.Char(string="Source Document")
|
||||
product_mrp_area_id = fields.Many2one(
|
||||
comodel_name="product.mrp.area",
|
||||
string="Product MRP Area",
|
||||
|
||||
@@ -52,6 +52,12 @@
|
||||
<field name="supply_qty" />
|
||||
<field name="final_on_hand_qty" />
|
||||
<field name="to_procure" />
|
||||
<button
|
||||
attrs="{'invisible': [('planned_order_ids', '=', [])]}"
|
||||
name="action_open_planned_orders"
|
||||
type="object"
|
||||
icon="fa-list"
|
||||
/>
|
||||
<field name="order_release_date" />
|
||||
<button
|
||||
title="Create Procurement"
|
||||
@@ -60,6 +66,7 @@
|
||||
type="action"
|
||||
attrs="{'invisible':[('to_procure','<=',0.0)]}"
|
||||
/>
|
||||
<field name="planned_order_ids" invisible="1" />
|
||||
<field name="supply_method" />
|
||||
<field name="main_supplier_id" optional="hide" />
|
||||
<field name="running_availability" />
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
attrs="{'invisible':[('mrp_origin', '!=', 'mv')]}"
|
||||
/>
|
||||
<field name="name" />
|
||||
<field name="origin" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="mrp_date" />
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<field name="model">mrp.planned.order</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree decoration-info="fixed != True">
|
||||
<field name="name" />
|
||||
<field name="origin" />
|
||||
<field name="product_mrp_area_id" />
|
||||
<field name="product_id" />
|
||||
<field name="mrp_area_id" />
|
||||
@@ -75,6 +77,7 @@
|
||||
<field name="model">mrp.planned.order</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="origin" />
|
||||
<field name="name" />
|
||||
<field name="product_id" />
|
||||
<field name="mrp_area_id" />
|
||||
|
||||
@@ -83,8 +83,8 @@ class MrpInventoryProcure(models.TransientModel):
|
||||
item.qty,
|
||||
item.uom_id,
|
||||
item.location_id,
|
||||
"MRP: " + str(self.env.user.login), # name?
|
||||
"MRP: " + str(self.env.user.login), # origin?
|
||||
"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,
|
||||
values,
|
||||
)
|
||||
|
||||
@@ -53,25 +53,28 @@ class MultiLevelMrp(models.TransientModel):
|
||||
po = po_line = None
|
||||
mo = origin = order_number = parent_product_id = None
|
||||
if move.purchase_line_id:
|
||||
order_number = move.purchase_line_id.order_id.name
|
||||
po = move.purchase_line_id.order_id
|
||||
order_number = po.origin or po.name
|
||||
origin = "po"
|
||||
po = move.purchase_line_id.order_id.id
|
||||
po_line = move.purchase_line_id.id
|
||||
elif move.production_id or move.raw_material_production_id:
|
||||
production = move.production_id or move.raw_material_production_id
|
||||
order_number = production.name
|
||||
order_number = production.origin or production.name
|
||||
origin = "mo"
|
||||
mo = production.id
|
||||
elif move.move_dest_ids:
|
||||
for move_dest_id in move.move_dest_ids.filtered("production_id"):
|
||||
order_number = move_dest_id.production_id.name
|
||||
production = move_dest_id.production_id
|
||||
order_number = production.origin or production.name
|
||||
origin = "mo"
|
||||
mo = move_dest_id.production_id.id
|
||||
parent_product_id = (
|
||||
move_dest_id.production_id.product_id or move_dest_id.product_id
|
||||
).id
|
||||
if not order_number:
|
||||
order_number = (move.picking_id or move).name
|
||||
source = (move.picking_id or move).origin
|
||||
order_number = source or (move.picking_id or move).name
|
||||
origin = "mv"
|
||||
# The date to display is based on the timezone of the warehouse.
|
||||
today_tz = area._datetime_to_date_tz()
|
||||
@@ -96,12 +99,13 @@ class MultiLevelMrp(models.TransientModel):
|
||||
"mrp_order_number": order_number,
|
||||
"parent_product_id": parent_product_id,
|
||||
"name": order_number,
|
||||
"origin": order_number,
|
||||
"state": move.state,
|
||||
}
|
||||
|
||||
@api.model
|
||||
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 {
|
||||
"product_mrp_area_id": product_mrp_area.id,
|
||||
@@ -111,12 +115,13 @@ class MultiLevelMrp(models.TransientModel):
|
||||
"mrp_action": product_mrp_area.supply_method,
|
||||
"qty_released": 0.0,
|
||||
"name": "Planned supply for: " + name,
|
||||
"origin": values.get("origin") or name,
|
||||
"fixed": False,
|
||||
}
|
||||
|
||||
@api.model
|
||||
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(
|
||||
bomline.product_id, product.mrp_area_id
|
||||
@@ -152,6 +157,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
).replace(
|
||||
"Demand Bom Explosion: Demand Bom Explosion: ", "Demand Bom Explosion: "
|
||||
),
|
||||
"origin": planned_order.origin,
|
||||
}
|
||||
|
||||
@api.model
|
||||
@@ -208,7 +214,13 @@ class MultiLevelMrp(models.TransientModel):
|
||||
)
|
||||
)
|
||||
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)
|
||||
if hasattr(action, "mrp_move_down_ids"):
|
||||
@@ -251,7 +263,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
qty = product_mrp_area_id._adjust_qty_to_order(qty_to_order)
|
||||
qty_to_order -= qty
|
||||
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)
|
||||
qty_ordered = qty_ordered + qty
|
||||
@@ -479,6 +491,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
last_qty = 0.00
|
||||
onhand = product_mrp_area.qty_available
|
||||
grouping_delta = product_mrp_area.mrp_nbr_days
|
||||
demand_origin = []
|
||||
for move in product_mrp_area.mrp_move_ids:
|
||||
if self._exclude_move(move):
|
||||
continue
|
||||
@@ -494,19 +507,27 @@ class MultiLevelMrp(models.TransientModel):
|
||||
or (onhand + last_qty) < product_mrp_area.mrp_minimum_stock
|
||||
)
|
||||
):
|
||||
name = "Grouped Demand for %d Days" % grouping_delta
|
||||
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
|
||||
cm = self.create_action(
|
||||
product_mrp_area_id=product_mrp_area,
|
||||
mrp_date=last_date,
|
||||
mrp_qty=qtytoorder,
|
||||
name=name,
|
||||
values=dict(origin=origin),
|
||||
)
|
||||
qty_ordered = cm.get("qty_ordered", 0.0)
|
||||
onhand = onhand + last_qty + qty_ordered
|
||||
last_date = None
|
||||
last_qty = 0.00
|
||||
nbr_create += 1
|
||||
demand_origin = []
|
||||
if (
|
||||
onhand + last_qty + move.mrp_qty
|
||||
) < product_mrp_area.mrp_minimum_stock or (
|
||||
@@ -520,15 +541,23 @@ class MultiLevelMrp(models.TransientModel):
|
||||
else:
|
||||
last_date = fields.Date.from_string(move.mrp_date)
|
||||
onhand += move.mrp_qty
|
||||
demand_origin.append(move.origin or move.name)
|
||||
|
||||
if last_date and last_qty != 0.00:
|
||||
name = "Grouped Demand for %d Days" % grouping_delta
|
||||
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
|
||||
cm = self.create_action(
|
||||
product_mrp_area_id=product_mrp_area,
|
||||
mrp_date=last_date,
|
||||
mrp_qty=qtytoorder,
|
||||
name=name,
|
||||
values=dict(origin=origin),
|
||||
)
|
||||
qty_ordered = cm.get("qty_ordered", 0.0)
|
||||
onhand += qty_ordered
|
||||
@@ -573,6 +602,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
mrp_date=move.mrp_date,
|
||||
mrp_qty=qtytoorder,
|
||||
name=move.name,
|
||||
values=dict(origin=move.origin),
|
||||
)
|
||||
qty_ordered = cm["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:
|
||||
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand
|
||||
name = _("Safety Stock")
|
||||
cm = self.create_action(
|
||||
product_mrp_area_id=product_mrp_area,
|
||||
mrp_date=date.today(),
|
||||
mrp_qty=qtytoorder,
|
||||
name="Minimum Stock",
|
||||
name=name,
|
||||
values=dict(origin=name),
|
||||
)
|
||||
qty_ordered = cm["qty_ordered"]
|
||||
onhand += qty_ordered
|
||||
|
||||
Reference in New Issue
Block a user