[REF] stock, sale_stock, purchase_stock: stock.uom_propagate config parameter refactor
Avoid duplicate code and instead use a new private function closes odoo/odoo#29266
This commit is contained in:
@@ -105,13 +105,9 @@ class ProcurementGroup(models.Model):
|
||||
qty_to_produce = ( order_qty / bom_kit.product_qty)
|
||||
boms, bom_sub_lines = bom_kit.explode(product_id, qty_to_produce)
|
||||
for bom_line, bom_line_data in bom_sub_lines:
|
||||
procurement_uom = bom_line.product_uom_id
|
||||
quant_uom = bom_line.product_id.uom_id
|
||||
component_qty = bom_line_data['qty']
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
if procurement_uom.id != quant_uom.id and get_param('stock.propagate_uom') != '1':
|
||||
component_qty = bom_line.product_uom_id._compute_quantity(bom_line_data['qty'], quant_uom, rounding_method='HALF-UP')
|
||||
procurement_uom = quant_uom
|
||||
bom_line_uom = bom_line.product_uom_id
|
||||
quant_uom = bom_line.product_id.uom_id
|
||||
component_qty, procurement_uom = bom_line_uom._adjust_uom_quantities(bom_line_data['qty'], quant_uom)
|
||||
super(ProcurementGroup, self).run(bom_line.product_id, component_qty, procurement_uom, location_id, name, origin, values)
|
||||
return True
|
||||
else:
|
||||
|
||||
@@ -359,14 +359,11 @@ class PurchaseOrderLine(models.Model):
|
||||
}
|
||||
diff_quantity = self.product_qty - qty
|
||||
if float_compare(diff_quantity, 0.0, precision_rounding=self.product_uom.rounding) > 0:
|
||||
po_line_uom = self.product_uom
|
||||
quant_uom = self.product_id.uom_id
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
if self.product_uom.id != quant_uom.id and get_param('stock.propagate_uom') != '1':
|
||||
product_qty = self.product_uom._compute_quantity(diff_quantity, quant_uom, rounding_method='HALF-UP')
|
||||
template['product_uom'] = quant_uom.id
|
||||
template['product_uom_qty'] = product_qty
|
||||
else:
|
||||
template['product_uom_qty'] = diff_quantity
|
||||
product_uom_qty, product_uom = po_line_uom._adjust_uom_quantities(diff_quantity, quant_uom)
|
||||
template['product_uom_qty'] = product_uom_qty
|
||||
template['product_uom'] = product_uom.id
|
||||
res.append(template)
|
||||
return res
|
||||
|
||||
|
||||
@@ -371,12 +371,9 @@ class SaleOrderLine(models.Model):
|
||||
values = line._prepare_procurement_values(group_id=group_id)
|
||||
product_qty = line.product_uom_qty - qty
|
||||
|
||||
procurement_uom = line.product_uom
|
||||
line_uom = line.product_uom
|
||||
quant_uom = line.product_id.uom_id
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
if procurement_uom.id != quant_uom.id and get_param('stock.propagate_uom') != '1':
|
||||
product_qty = line.product_uom._compute_quantity(product_qty, quant_uom, rounding_method='HALF-UP')
|
||||
procurement_uom = quant_uom
|
||||
product_qty, procurement_uom = line_uom._adjust_uom_quantities(product_qty, quant_uom)
|
||||
|
||||
try:
|
||||
self.env['procurement.group'].run(line.product_id, product_qty, procurement_uom, line.order_id.partner_shipping_id.property_stock_customer, line.name, line.order_id.name, values)
|
||||
|
||||
@@ -653,3 +653,15 @@ class UoM(models.Model):
|
||||
"currently reserved."
|
||||
))
|
||||
return super(UoM, self).write(values)
|
||||
|
||||
def _adjust_uom_quantities(self, qty, quant_uom):
|
||||
""" This method adjust the quantities of a procurement if its UoM isn't the same
|
||||
as the one of the quant and the parameter 'propagate_uom' is not set.
|
||||
"""
|
||||
procurement_uom = self
|
||||
computed_qty = qty
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
if procurement_uom.id != quant_uom.id and get_param('stock.propagate_uom') != '1':
|
||||
computed_qty = self._compute_quantity(qty, quant_uom, rounding_method='HALF-UP')
|
||||
procurement_uom = quant_uom
|
||||
return (computed_qty, procurement_uom)
|
||||
|
||||
Reference in New Issue
Block a user