Skip to content
Snippets Groups Projects
Commit b4bbf30b authored by Adrien Widart (awt)'s avatar Adrien Widart (awt)
Browse files

[FIX] mrp_subcontracting: find MO on landed cost form


In case of subcontracting, it is not straightforward for a user to
select the appropriate MO on the landed costs form.

To reproduce the issue:
(Need stock_landed_costs)
1. Create two products P_compo, P_finished
    - Storable
    - P_finished:
        - Add a vendor V
2. Create a BoM:
   - Product: P_finished
   - Type: Subcontracting
   - Subcontractors: V
   - Components: 1 x P_compo
3. Process a receipt R:
   - From: V
   - Operations: 1 x P
4. Open the form to create a landed cost
5. Set the Apply On to Manufacturing orders
6. Try to find R

Error: There isn't any reference for R. There is actually the
reference of the manufacturing order (for instance WH/SBC/00001) but
the user can't know that this MO is related to R.

A part of the solution is the partial backport of [1]. Thanks to
this commit, the method `name_get` of the MO will include the name
of the associated receipt in case of subcontracting.

[1] 0e26ed69

OPW-3070543

closes odoo/odoo#109431

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent f662051e
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
from collections import defaultdict
from odoo import fields, models, _, api
from odoo.exceptions import UserError
from odoo.osv import expression
from odoo.tools.float_utils import float_compare, float_is_zero
......@@ -14,6 +15,32 @@ class MrpProduction(models.Model):
'stock.move.line', string="Detail Component", readonly=False,
inverse='_inverse_move_line_raw_ids', compute='_compute_move_line_raw_ids'
)
incoming_picking = fields.Many2one(related='move_finished_ids.move_dest_ids.picking_id')
@api.depends('name')
def name_get(self):
return [
(record.id, "%s (%s)" % (record.incoming_picking.name, record.name)) if record.bom_id.type == 'subcontract'
else (record.id, record.name) for record in self
]
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
args = list(args or [])
if name == '' and operator == 'ilike':
return self._search(args, limit=limit, access_rights_uid=name_get_uid)
# search through MO
domain = [(self._rec_name, operator, name)]
# search through transfers
picking_rec_name = self.env['stock.picking']._rec_name
picking_domain = [('bom_id.type', '=', 'subcontract'), ('incoming_picking.%s' % picking_rec_name, operator, name)]
domain = expression.OR([domain, picking_domain])
args = expression.AND([args, domain])
return self._search(args, limit=limit, access_rights_uid=name_get_uid)
@api.depends('move_raw_ids.move_line_ids')
def _compute_move_line_raw_ids(self):
......
......@@ -492,6 +492,27 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon):
mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)])
self.assertEqual(len(mo), 1)
def test_mo_name(self):
receipt_form = Form(self.env['stock.picking'])
receipt_form.picking_type_id = self.env.ref('stock.picking_type_in')
receipt_form.partner_id = self.subcontractor_partner1
with receipt_form.move_ids_without_package.new() as move:
move.product_id = self.finished
move.product_uom_qty = 1
receipt = receipt_form.save()
receipt.action_confirm()
mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)])
display_name = mo.display_name
self.assertIn(receipt.name, display_name, "If subcontracted, the name of a MO should contain the associated receipt name")
self.assertIn(mo.name, display_name)
for key_search in [mo.name, receipt.name]:
res = mo.name_search(key_search)
self.assertTrue(res, 'When looking for "%s", it should find something' % key_search)
self.assertEqual(res[0][0], mo.id, 'When looking for "%s", it should find the MO processed above' % key_search)
class TestSubcontractingTracking(TransactionCase):
def setUp(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment