Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] mrp: byproduct #31569

Closed
wants to merge 22 commits into from

Conversation

Projects
None yet
5 participants
@amoyaux
Copy link
Contributor

amoyaux commented Mar 4, 2019

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo robodoo added the seen 🙂 label Mar 4, 2019

@C3POdoo C3POdoo added the RD label Mar 4, 2019

addons/mrp/models/mrp_production.py Outdated
'warehouse_id': production.location_dest_id.get_warehouse().id,
'origin': production.name,
'unit_factor': qty1 / (production.product_qty - production.qty_produced),
'propagate': self.propagate,

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

production.propagate

addons/mrp/models/mrp_production.py Outdated
'origin': production.name,
'unit_factor': qty1 / (production.product_qty - production.qty_produced),
'propagate': self.propagate,
'group_id': self.move_dest_ids and self.move_dest_ids.mapped('group_id')[0].id or self.procurement_group_id.id,

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

self -> production

Show resolved Hide resolved addons/mrp/models/mrp_production.py Outdated
addons/mrp/models/mrp_production.py Outdated
'subproduct_id': sub_product.id
}
move = Move.create(data)
move._action_confirm()

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

production.action_confirm already call move.action_confirm

addons/mrp/models/mrp_bom.py Outdated
if self.product_uom_id and self.product_id and self.product_uom_id.category_id != self.product_id.uom_id.category_id:
res['warning'] = {
'title': _('Warning'),
'message': _('The unit of measure you chose is in a different category than the product unit of measure.')

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

typo 'choose'

addons/mrp/models/mrp_production.py Outdated
if not (raw_finished_lots <= finished_lots):
lots_short = raw_finished_lots - finished_lots
error_msg = _(
'Some raw materials have been consumed for a lot/serial number that has not been produced. '
'Unlock the MO and click on the components lines to correct it.\n'
'List of the components:\n'
)
move_lines = self.move_raw_ids.mapped('move_line_ids').filtered(lambda x: x.lot_produced_id in lots_short)
move_lines = self.move_raw_ids.mapped('move_line_ids').filtered(lambda x: x.lot_produced_ids in lots_short)

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

lot_produced_ids is a recordset now, 'in' won't work

addons/mrp/models/mrp_workorder.py Outdated
move.state not in ('done', 'cancel')
).workorder_id = self.id
self.production_id.move_finished_ids.move_line_ids.filtered(
lambda ml: ml.product_id == self.product_id and

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

If we filtered on self.product_id, why filtering on 'not workorder_id' too?

@@ -218,7 +218,7 @@ def test_unbuild_with_comnsumed_lot(self):
unbuild_order.action_unbuild()

self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location), 2, 'You should have consumed 3 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1, self.stock_location, lot_id=lot), 92, 'You should have 80 products in stock')

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

lol

addons/mrp/views/mrp_bom_views.xml Outdated
<field name="attachments_count" class="text-left"
string=" "/>
<button name="action_see_attachments" type="object" icon="fa-files-o" aria-label="attachment" title="attachment" class="float-right"/>
<field name="attachments_count" class="text-left" string=" "/>

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

? why

addons/mrp/wizard/mrp_product_produce.py Outdated
@@ -96,27 +103,32 @@ def _get_todo(self, production):
def _record_production(self):
# Check all the product_produce line have a move id (the user can add product
# to consume directly in the wizard)
for line in self.workorder_line_ids:
for line in self.raw_workorder_line_ids | self.finished_workorder_line_ids:

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 7, 2019

Contributor

workorder_line_ids is not the union ?

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch 5 times, most recently from 8bd6d87 to 43c681a Mar 11, 2019

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch from b4f0df8 to 37b835c Mar 19, 2019

@robodoo robodoo added the CI 🤖 label Mar 19, 2019

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch from f9fbca2 to 0e6068b Mar 20, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 20, 2019

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch 2 times, most recently from 1357df7 to 864e677 Mar 25, 2019

@robodoo robodoo added the CI 🤖 label Mar 25, 2019

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch from de5eb9c to 832a547 Mar 25, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 25, 2019

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch from 4b42f97 to 489a29b Mar 26, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 26, 2019

self.workorder_line_ids -= line_values['to_delete']
for workorder_field, list_vals in line_values['to_create'].items():
for vals in list_vals:
self[workorder_field] |= self[workorder_field].new(vals)

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

.new est api.model donc je ne pense pas que tu doive séparer les deux types de ligne

if len(workorders) == len(bom.routing_id.operation_ids):
moves_raw |= self.move_raw_ids.filtered(lambda move: not move.operation_id)
moves_finished = self.move_finished_ids.filtered(lambda move: move.operation_id == operation) #TODO: code does nothing, unless maybe by_products?
moves_finished |= self.move_finished_ids.filtered(lambda move: move.product_id != self.product_id and not move.operation_id)

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

move.byproduct_id

@@ -70,7 +70,10 @@ 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')
unit_factor = fields.Float('Unit Factor')
byproduct_id = fields.Many2one(
'mrp.bom.byproduct', 'Subproduct',

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

'Byproduct'

self.workorder_line_ids -= line_values['to_delete']
for workorder_field, list_vals in line_values['to_create'].items():
for vals in list_vals:
self[workorder_field] |= self[workorder_field].new(vals)

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

new is api.model. You could leave self.workorder_line_ids.new(vals)

produce_moves = self._generate_produce_moves()

finished_move = consume_moves.filtered(lambda m: m.product_id == self.product_id)
consume_moves -= finished_move

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

why not change _generate_consume_moves and _generate_consume_moves into one function _get_moves that return 3 record sets. It will be cleaner action_unbuild

@@ -80,7 +80,11 @@ class MrpWorkorder(models.Model):
worksheet = fields.Binary(
'Worksheet', related='operation_id.worksheet', readonly=True)
move_raw_ids = fields.One2many(
'stock.move', 'workorder_id', 'Moves')
'stock.move', 'workorder_id', 'Raw Moves',

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

You made a domain for stock.move but 2 foreign keys for wo lines. Berk

qty_to_consume = move.product_uom._compute_quantity(
self.qty_producing * move.unit_factor,
move.product_id.uom_id,
round=False
)
line_values = self._generate_lines_values(move, qty_to_consume)
self.workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
if move in self.production_id.move_raw_ids:
self.raw_workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

create is api.model you can leave self.env['mrp.workorder.line'].create(line_values)

@@ -166,6 +166,18 @@
<field name="move_id" invisible="1"/>
</tree>
</field>
<h4 attrs="{'invisible': [('finished_workorder_line_ids', '=', [])]}">Finished Products</h4>

This comment has been minimized.

Copy link
@Whenrow

Whenrow Mar 28, 2019

Contributor

'ByProduct' ?

Whenrow added some commits Feb 20, 2019

[IMP] mrp: block creating lot from workorder/produce wizard
When registering lot or serial number for a component in a workorder,
the manufacturer can create it on on the fly. We would like to restrict
this ability.
This commit blocks the creating by default. but leave the possibility to
check a new checkbox on the manufacturing picking type to allow the
creation of lot and serial number inside the production process.

Task : 1891864
[IMP] mrp: multiple finished product lots
This commit allows the user in charge of manufacturing products to
split his production into different lots in a workorder. Entering a
lot in a workorder will add constraint to all the next ones. It will
also prefil the final lot field for futur wo as well as the corresponding quantity

Task : 1891864

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 29, 2019

amoyaux added some commits Mar 29, 2019

m
@@ -71,7 +71,7 @@ class StockMove(models.Model):
# Quantities to process, in normalized UoMs
bom_line_id = fields.Many2one('mrp.bom.line', 'BoM Line')
byproduct_id = fields.Many2one(
'mrp.bom.byproduct', 'Subproduct',
'mrp.bom.byproduct', 'Byproduct',
help="Subproduct line that generated the move in a manufacturing order")

This comment has been minimized.

Copy link
@sle-odoo

sle-odoo Apr 1, 2019

Contributor

help should also use byproduct right?

@api.depends('raw_workorder_line_ids', 'finished_workorder_line_ids')
def _compute_workorder_line_ids(self):
for workorder in self:
workorder.workorder_line_ids = workorder.raw_workorder_line_ids | workorder.finished_workorder_line_ids

This comment has been minimized.

Copy link
@sle-odoo

sle-odoo Apr 1, 2019

Contributor

i don't think we need a compute here, an helper would be enough

amoyaux and others added some commits Apr 1, 2019

m
m
m
[REF] mrp: add groups for byproducts
Since mrp_byproduct is in mrp. We want to keep the byproduct as an
additional feature. So this commit add a group and hide byproducts
tab in views.
[IMP] mrp: byproduct in produce wizard
[IMP] mrp: select operation to create byproduct
[IMP] mrp: unbuild byproducts
Unbuild a manufacturing order only undo the final product and its
components. The byproduct created will not be undo with the correct
ratio. This commit will allow to undo a ratio of byproducts for a
specific MO or base on the BoM if the byproducts are not tracked.
[FIX] mrp: tracability on extra move line
Usecase to reproduce:
- BoM with final product tracked by SN
- Produce wizard add a component tracked by SN (not from BoM)
- Produce and mark the MO as done

The tracability report do not show the extra component used.

It happens because _record_production call _action_done on moves raw
and finished. _action_done create extra move with moves that created
more than expected (the purpose is to trigger rules). However in stock
the new move is created then merged in its parent but in mrp moves are
not merge. _record production set the tracability for initial moves but
ignore the extra moves created. So the tracability report is not
complete.

Fix it by catching the new moves created after _action_done and set
the consume_line_ids for the extra moves also.
[FIX] mrp: by-products typo + default type on product
Be consistent with by-products and byproducts. Only use by-products.
When a product is created from the BoM view, it has a default type
as storable product, set the same type when the product is created
from by-products tab.
[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.
m

@amoyaux amoyaux force-pushed the odoo-dev:master-byproduct-arm branch from d4bc479 to 8eee330 Apr 4, 2019

@robodoo robodoo removed the CI 🤖 label Apr 4, 2019

@amoyaux amoyaux changed the title Master byproduct arm [REF] mrp: byproduct Apr 9, 2019

@amoyaux

This comment has been minimized.

Copy link
Contributor Author

amoyaux commented Apr 9, 2019

check PR #32540

@amoyaux amoyaux closed this Apr 9, 2019

@robodoo robodoo added the closed 💔 label Apr 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.