mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[11.0][IMP] mrp_multi_level: improve usability
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
from datetime import timedelta, date
|
||||
|
||||
|
||||
class MrpInventory(models.Model):
|
||||
_name = 'mrp.inventory'
|
||||
@@ -12,16 +14,14 @@ class MrpInventory(models.Model):
|
||||
_description = 'MRP inventory projections'
|
||||
_rec_name = 'mrp_product_id'
|
||||
|
||||
# TODO: uom??
|
||||
# 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
|
||||
# TODO: substract qty already procured.
|
||||
# TODO: show a LT based on the procure method?
|
||||
# TODO: add to_procure_date
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name='mrp.area', string='MRP Area',
|
||||
related='mrp_product_id.mrp_area_id',
|
||||
related='mrp_product_id.mrp_area_id', store=True,
|
||||
)
|
||||
mrp_product_id = fields.Many2one(
|
||||
comodel_name='mrp.product', string='Product',
|
||||
@@ -37,8 +37,31 @@ class MrpInventory(models.Model):
|
||||
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')
|
||||
date_to_procure = fields.Date(
|
||||
string="Date to Procure",
|
||||
compute="_compute_date_to_procure",
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_uom_id(self):
|
||||
for rec in self:
|
||||
rec.uom_id = rec.mrp_product_id.product_id.uom_id
|
||||
|
||||
@api.multi
|
||||
@api.depends('mrp_product_id', 'mrp_product_id.main_supplierinfo_id',
|
||||
'mrp_product_id.mrp_lead_time')
|
||||
def _compute_date_to_procure(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
|
||||
# TODO: 'move' supply method
|
||||
date_to_procure = fields.Date.from_string(
|
||||
rec.date) - timedelta(days=delay)
|
||||
if date_to_procure < today:
|
||||
date_to_procure = today
|
||||
rec.date_to_procure = date_to_procure
|
||||
|
||||
@@ -20,6 +20,10 @@ class MrpProduct(models.Model):
|
||||
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(
|
||||
@@ -101,6 +105,7 @@ class MrpProduct(models.Model):
|
||||
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
|
||||
|
||||
@@ -6,17 +6,23 @@
|
||||
<field name="model">mrp.inventory</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="MRP Area">
|
||||
<group>
|
||||
<field name="mrp_area_id"/>
|
||||
<field name="mrp_product_id"/>
|
||||
<field name="date"/>
|
||||
<field name="initial_on_hand_qty"/>
|
||||
<field name="demand_qty"/>
|
||||
<field name="supply_qty"/>
|
||||
<field name="final_on_hand_qty"/>
|
||||
<field name="to_procure"/>
|
||||
</group>
|
||||
<form string="MRP Inventory" create="false" edit="false">
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="mrp_area_id"/>
|
||||
<field name="mrp_product_id"/>
|
||||
<field name="date"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="initial_on_hand_qty"/>
|
||||
<field name="demand_qty"/>
|
||||
<field name="supply_qty"/>
|
||||
<field name="final_on_hand_qty"/>
|
||||
<field name="to_procure"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
@@ -24,9 +30,9 @@
|
||||
<record model="ir.ui.view" id="mrp_inventory_tree">
|
||||
<field name="name">mrp.inventory.tree</field>
|
||||
<field name="model">mrp.inventory</field>
|
||||
<field name="type">form</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="MRP Inventory">
|
||||
<tree string="MRP Inventory" create="false">
|
||||
<field name="mrp_area_id"/>
|
||||
<field name="mrp_product_id"/>
|
||||
<field name="date"/>
|
||||
@@ -35,7 +41,7 @@
|
||||
<field name="supply_qty"/>
|
||||
<field name="final_on_hand_qty"/>
|
||||
<field name="to_procure"/>
|
||||
<!--TODO: use same procurement wizard as ddmrp?-->
|
||||
<field name="date_to_procure"/>
|
||||
<button string="Create Procurement"
|
||||
name="%(mrp_multi_level.act_mrp_inventory_procure)d"
|
||||
icon="fa-cogs" type="action"
|
||||
@@ -44,6 +50,31 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_mrp_inventory_pivot" model="ir.ui.view">
|
||||
<field name="name">mrp.inventory.pivot</field>
|
||||
<field name="model">mrp.inventory</field>
|
||||
<field name="arch" type="xml">
|
||||
<pivot string="MRP Inventory">
|
||||
<field name="final_on_hand_qty" type="measure"/>
|
||||
<field name="mrp_area_id" type="row"/>
|
||||
<field name="mrp_product_id" type="row"/>
|
||||
<field name="date" interval="day" type="col"/>
|
||||
</pivot>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_mrp_inventory_graph" model="ir.ui.view">
|
||||
<field name="name">mrp.inventory.graph</field>
|
||||
<field name="model">mrp.inventory</field>
|
||||
<field name="arch" type="xml">
|
||||
<graph string="MRP Inventory" type="line">
|
||||
<field name="final_on_hand_qty" type="measure"/>
|
||||
<field name="date" interval="day" type="row"/>
|
||||
<field name="mrp_product_id" type="row"/>
|
||||
</graph>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="mrp_inventory_search">
|
||||
<field name="name">mrp.inventory.search</field>
|
||||
<field name="model">mrp.inventory</field>
|
||||
@@ -51,8 +82,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="MRP Inventory">
|
||||
<group name="select" expand="0" string="Selection...">
|
||||
<field name="mrp_product_id" select='1'/>
|
||||
<field name="mrp_area_id" select='1'/>
|
||||
<field name="mrp_product_id"/>
|
||||
<field name="mrp_area_id"/>
|
||||
</group>
|
||||
<separator/>
|
||||
<filter string="To Procure" name="filter_to_procure"
|
||||
@@ -63,35 +94,25 @@
|
||||
context="{'group_by':'mrp_product_id'}"/>
|
||||
<filter string="MRP Area"
|
||||
context="{'group_by':'mrp_area_id'}"/>
|
||||
<filter string="Date to Procure (By Day)"
|
||||
context="{'group_by':'date_to_procure:day'}"/>
|
||||
<filter string="Date to Procure (By Week)"
|
||||
context="{'group_by':'date_to_procure:week'}"/>
|
||||
<filter string="Date to Procure (By Month)"
|
||||
context="{'group_by':'date_to_procure:month'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="mrp_inventory_action">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="name">MRP Inventory</field>
|
||||
<field name="res_model">mrp.inventory</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_mode">tree,form,pivot,graph</field>
|
||||
<field name="view_id" ref="mrp_inventory_tree"/>
|
||||
<field name="search_view_id" ref="mrp_inventory_search"/>
|
||||
<field name="act_window_id" ref="mrp_inventory_form"/>
|
||||
</record>
|
||||
|
||||
<!--TODO: remove?-->
|
||||
<record model="ir.actions.act_window.view" id="mrp_inventory_form_action">
|
||||
<field name="sequence" eval="22"/>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="mrp_inventory_form"/>
|
||||
<field name="act_window_id" ref="mrp_inventory_action"/>
|
||||
</record>
|
||||
<record model="ir.actions.act_window.view" id="mrp_inventory_tree_action">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_id" ref="mrp_inventory_tree"/>
|
||||
<field name="act_window_id" ref="mrp_inventory_action"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -36,7 +36,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
'product_id': product.id,
|
||||
'mrp_qty_available': product.qty_available,
|
||||
'mrp_llc': product.llc,
|
||||
'name': product.name,
|
||||
'name': '[%s] %s' % (mrp_area.name, product.display_name),
|
||||
}
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user