[11.0][IMP] mrp_multi_level: improve usability

This commit is contained in:
Lois Rilo
2018-06-21 14:44:02 +02:00
committed by davidborromeo
parent a49f269bf0
commit ff124b2e2b
4 changed files with 86 additions and 37 deletions

View File

@@ -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

View File

@@ -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