- Add the concept of 'Days to Prepare MO' in mrp, similar to 'Days to Purchase' but defined at the product level. Both concepts are merged into Days to Order at the orderpoint level, taking the value of Days to Purchase for orderpoints with a buy route and Days to Prepare MO for orderpoint with a manufacturing route. - Add the concept of 'Visibility Days' on orderpoints. The idea is to avoid to create through reordering rules multiple small orders for the same product on a small time frame but rather to order directly a bigger quantity. When Visibility Days are defined, the quantity of the orders created by a RR is not the quantity forecasted at Today + Lead times (quantity that triggered the order according to the RR), but the quantity forecasted at Today + Lead Times + Visibility days. The Visibility Days are different for purchase and manufacturing. Changing the route of the orderpoint will change its value. They can be defined at the company level and further fine-tuned on the orderpoint. In case of change of the parameters at the company level, only orderpoints without a specific value of Visibility Days will be changed. - Alignement between Manufacturing and Purchase Security Lead Time (previously the Manufacturing Security Lead time didn't impact the procurement date, instead the manufacturing time was made longer). closes odoo/odoo#86682 Task-id: 2738838 Pr: https://github.com/odoo/odoo/pull/86682 Related: odoo/upgrade#3415 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
40 lines
2.3 KiB
Python
40 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
from odoo import _, models
|
|
from odoo.tools.float_utils import float_is_zero
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class StockMove(models.Model):
|
|
_inherit = 'stock.move'
|
|
|
|
def _prepare_phantom_move_values(self, bom_line, product_qty, quantity_done):
|
|
vals = super(StockMove, self)._prepare_phantom_move_values(bom_line, product_qty, quantity_done)
|
|
if self.purchase_line_id:
|
|
vals['purchase_line_id'] = self.purchase_line_id.id
|
|
return vals
|
|
|
|
def _get_valuation_price_and_qty(self, related_aml, to_curr):
|
|
valuation_price_unit_total, valuation_total_qty = super()._get_valuation_price_and_qty(related_aml, to_curr)
|
|
boms = self.env['mrp.bom']._bom_find(related_aml.product_id, company_id=related_aml.company_id.id, bom_type='phantom')
|
|
if related_aml.product_id in boms:
|
|
kit_bom = boms[related_aml.product_id]
|
|
order_qty = related_aml.product_id.uom_id._compute_quantity(related_aml.quantity, kit_bom.product_uom_id)
|
|
filters = {
|
|
'incoming_moves': lambda m: m.location_id.usage == 'supplier' and (not m.origin_returned_move_id or (m.origin_returned_move_id and m.to_refund)),
|
|
'outgoing_moves': lambda m: m.location_id.usage != 'supplier' and m.to_refund
|
|
}
|
|
valuation_total_qty = self._compute_kit_quantities(related_aml.product_id, order_qty, kit_bom, filters)
|
|
valuation_total_qty = kit_bom.product_uom_id._compute_quantity(valuation_total_qty, related_aml.product_id.uom_id)
|
|
if float_is_zero(valuation_total_qty, precision_rounding=related_aml.product_uom_id.rounding or related_aml.product_id.uom_id.rounding):
|
|
raise UserError(_('Odoo is not able to generate the anglo saxon entries. The total valuation of %s is zero.') % related_aml.product_id.display_name)
|
|
return valuation_price_unit_total, valuation_total_qty
|
|
|
|
def _get_mto_procurement_date(self):
|
|
date = super()._get_mto_procurement_date()
|
|
if 'buy' in self.product_id._get_rules_from_location(self.location_id).mapped('action'):
|
|
date -= relativedelta(days=self.company_id.po_lead)
|
|
return date
|