Skip to content
Permalink
Browse files

[REF] mrp: rename subproduct in byproduct

subproduct and byproduct are both used in code.
However the UI always shows by-product only.
Rename sub.product, sub_product,... in byproduct
in order to use the same term everywhere.

closes #32540

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
  • Loading branch information...
amoyaux committed Mar 26, 2019
1 parent b5780cf commit 12da02d161e02d7b0d5508f96e401a03ec478b9c
@@ -36,7 +36,7 @@ def _get_default_product_uom_id(self):
domain="['&', ('product_tmpl_id', '=', product_tmpl_id), ('type', 'in', ['product', 'consu'])]",
help="If a product variant is defined the BOM is available only for this product.")
bom_line_ids = fields.One2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True)
sub_products = fields.One2many('mrp.subproduct', 'bom_id', 'Byproducts', copy=True)
byproduct_ids = fields.One2many('mrp.bom.byproduct', 'bom_id', 'By-products', copy=True)
product_qty = fields.Float(
'Quantity', default=1.0,
digits=dp.get_precision('Unit of Measure'), required=True)
@@ -360,8 +360,8 @@ def action_see_attachments(self):
}


class MrpSubProduct(models.Model):
_name = 'mrp.subproduct'
class MrpByProduct(models.Model):
_name = 'mrp.bom.byproduct'
_description = 'Byproduct'

product_id = fields.Many2one('product.product', 'By-product', required=True)
@@ -463,13 +463,13 @@ def action_toggle_is_locked(self):
self.is_locked = not self.is_locked
return True

def _get_finished_move_value(self, product_id, product_uom_qty, product_uom, operation_id=False, subproduct_id=False):
def _get_finished_move_value(self, product_id, product_uom_qty, product_uom, operation_id=False, byproduct_id=False):
return {
'product_id': product_id,
'product_uom_qty': product_uom_qty,
'product_uom': product_uom,
'operation_id': operation_id,
'subproduct_id': subproduct_id,
'byproduct_id': byproduct_id,
'unit_factor': product_uom_qty / self.product_qty,
'name': self.name,
'date': self.date_planned_start,
@@ -488,12 +488,12 @@ def _get_finished_move_value(self, product_id, product_uom_qty, product_uom, ope

def _generate_finished_moves(self):
moves_values = [self._get_finished_move_value(self.product_id.id, self.product_qty, self.product_uom_id.id)]
for sub_product in self.bom_id.sub_products:
for byproduct in self.bom_id.byproduct_ids:
product_uom_factor = self.product_uom_id._compute_quantity(self.product_qty, self.bom_id.product_uom_id)
qty = sub_product.product_qty * (product_uom_factor / self.bom_id.product_qty)
move_values = self._get_finished_move_value(sub_product.product_id.id,
qty, sub_product.product_uom_id.id, sub_product.operation_id.id,
sub_product.id)
qty = byproduct.product_qty * (product_uom_factor / self.bom_id.product_qty)
move_values = self._get_finished_move_value(byproduct.product_id.id,
qty, byproduct.product_uom_id.id, byproduct.operation_id.id,
byproduct.id)
moves_values.append(move_values)
moves = self.env['stock.move'].create(moves_values)
return moves
@@ -179,9 +179,9 @@ def _generate_consume_moves(self):
else:
factor = unbuild.product_uom_id._compute_quantity(unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
moves += unbuild._generate_move_from_bom_line(self.product_id, self.product_uom_id, unbuild.product_qty)
for byproduct in unbuild.bom_id.sub_products:
for byproduct in unbuild.bom_id.byproduct_ids:
quantity = byproduct.product_qty * factor
moves += unbuild._generate_move_from_bom_line(byproduct.product_id, byproduct.product_uom_id, quantity, subproduct_id=byproduct.id)
moves += unbuild._generate_move_from_bom_line(byproduct.product_id, byproduct.product_uom_id, quantity, byproduct_id=byproduct.id)
return moves

def _generate_produce_moves(self):
@@ -213,15 +213,15 @@ def _generate_move_from_existing_move(self, move, factor, location_id, location_
'unbuild_id': self.id,
})

def _generate_move_from_bom_line(self, product, product_uom, quantity, bom_line_id=False, subproduct_id=False):
def _generate_move_from_bom_line(self, product, product_uom, quantity, bom_line_id=False, byproduct_id=False):
location_id = bom_line_id and product.property_stock_production or self.location_id
location_dest_id = bom_line_id and self.location_dest_id or product.property_stock_production
warehouse = location_dest_id.get_warehouse()
return self.env['stock.move'].create({
'name': self.name,
'date': self.create_date,
'bom_line_id': bom_line_id,
'subproduct_id': subproduct_id,
'byproduct_id': byproduct_id,
'product_id': product.id,
'product_uom_qty': quantity,
'product_uom': product_uom.id,
@@ -70,9 +70,9 @@ class StockMove(models.Model):
'mrp.workorder', 'Work Order To Consume')
# Quantities to process, in normalized UoMs
bom_line_id = fields.Many2one('mrp.bom.line', 'BoM Line')
subproduct_id = fields.Many2one(
'mrp.subproduct', 'Subproduct',
help="Subproduct line that generated the move in a manufacturing order")
byproduct_id = fields.Many2one(
'mrp.bom.byproduct', 'By-products',
help="By-product line that generated the move in a manufacturing order")
unit_factor = fields.Float('Unit Factor', default=1)
is_done = fields.Boolean(
'Done', compute='_compute_is_done',
@@ -8,15 +8,15 @@ access_mrp_routing,mrp.routing,model_mrp_routing,mrp.group_mrp_user,1,0,0,0
access_mrp_routing_workcenter,mrp.routing.workcenter,model_mrp_routing_workcenter,mrp.group_mrp_user,1,0,0,0
access_mrp_bom,mrp.bom,model_mrp_bom,group_mrp_user,1,0,0,0
access_mrp_bom_line,mrp.bom.line,model_mrp_bom_line,group_mrp_user,1,0,0,0
access_mrp_subproduct_user,mrp.subproduct,model_mrp_subproduct,mrp.group_mrp_user,1,0,0,0
access_mrp_bom_byproduct_user,mrp.bom.byproduct,model_mrp_bom_byproduct,mrp.group_mrp_user,1,0,0,0
access_mrp_production,mrp.production user,model_mrp_production,mrp.group_mrp_user,1,1,1,1
access_mrp_workcenter_manager,mrp.workcenter.manager,model_mrp_workcenter,mrp.group_mrp_manager,1,1,1,1
access_mrp_resource_manager,access_mrp_resource manager,resource.model_resource_resource,mrp.group_mrp_manager,1,1,1,1
access_mrp_routing_manager,mrp.routing.manager,model_mrp_routing,mrp.group_mrp_manager,1,1,1,1
access_mrp_routing_workcenter_manager,mrp.routing.workcenter.manager,model_mrp_routing_workcenter,mrp.group_mrp_manager,1,1,1,1
access_mrp_bom_manager,mrp.bom.manager,model_mrp_bom,mrp.group_mrp_manager,1,1,1,1
access_mrp_bom_line_manager,mrp.bom.line.manager,model_mrp_bom_line,mrp.group_mrp_manager,1,1,1,1
access_mrp_subproduct_manager,mrp.subproduct manager,model_mrp_subproduct,mrp.group_mrp_manager,1,1,1,1
access_mrp_bom_byproduct_manager,mrp.bom.byproduct manager,model_mrp_bom_byproduct,mrp.group_mrp_manager,1,1,1,1
access_stock_location_mrp_worker,stock.location mrp_worker,stock.model_stock_location,mrp.group_mrp_user,1,0,0,0
access_stock_move_mrp_worker,stock.move mrp_worker,stock.model_stock_move,mrp.group_mrp_user,1,1,1,0
access_stock_picking_mrp_worker,stock.picking mrp_worker,stock.model_stock_picking,mrp.group_mrp_user,1,1,1,1
@@ -45,7 +45,7 @@ def test_00_mrp_byproduct(self):
'type': 'normal',
'product_uom_id': self.uom_unit_id,
'bom_line_ids': [(0, 0, {'product_id': self.product_c_id, 'product_uom_id': self.uom_unit_id, 'product_qty': 2})],
'sub_products': [(0, 0, {'product_id': self.product_b.id, 'product_uom_id': self.uom_unit_id, 'product_qty': 1})]
'byproduct_ids': [(0, 0, {'product_id': self.product_b.id, 'product_uom_id': self.uom_unit_id, 'product_qty': 1})]
})

# Create production order for product A
@@ -150,7 +150,7 @@ def test_tracking_on_byproducts(self):
(0, 0, {'product_id': product_1.id, 'product_qty': 1}),
(0, 0, {'product_id': product_2.id, 'product_qty': 1})
],
'sub_products': [
'byproduct_ids': [
(0, 0, {'product_id': byproduct_1.id, 'product_qty': 1, 'product_uom_id': byproduct_1.uom_id.id}),
(0, 0, {'product_id': byproduct_2.id, 'product_qty': 1, 'product_uom_id': byproduct_2.uom_id.id})
]})
@@ -70,7 +70,7 @@
</field>
</page>
<page string="By-products" attrs="{'invisible': [('type','!=','normal')]}" groups="mrp.group_mrp_byproducts">
<field name="sub_products">
<field name="byproduct_ids">
<tree string="By-products" editable="top">
<field name="product_id" context="{'default_type': 'product'}"/>
<field name="product_qty"/>

0 comments on commit 12da02d

Please sign in to comment.
You can’t perform that action at this time.