From 3d36c9bcd536f2c2284af37fdc3dbe48fef625b5 Mon Sep 17 00:00:00 2001 From: mpanarin Date: Fri, 16 Mar 2018 16:24:54 +0200 Subject: [PATCH] [IMP] make an onchange for location_id, fix readme --- mrp_bom_location/README.rst | 4 ++++ mrp_bom_location/models/mrp_bom.py | 15 ++++++++++----- mrp_bom_location/report/bom_structure.py | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mrp_bom_location/README.rst b/mrp_bom_location/README.rst index ba1c833f5..2179a654b 100644 --- a/mrp_bom_location/README.rst +++ b/mrp_bom_location/README.rst @@ -20,6 +20,9 @@ Usage To use this module, you need to: #. Go to *Manufacturing > Bill of Materials*. +#. Pick or create one of them. +#. You will see a new field to fill called "Location". +#. One the structure report *BOM > Print > BOM Structure* location field is present .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot @@ -45,6 +48,7 @@ Contributors ------------ * Lois Rilo +* Mykhailo Panarin Do not contact contributors directly about support or help with technical issues. diff --git a/mrp_bom_location/models/mrp_bom.py b/mrp_bom_location/models/mrp_bom.py index ea260a498..10a3ae7f8 100644 --- a/mrp_bom_location/models/mrp_bom.py +++ b/mrp_bom_location/models/mrp_bom.py @@ -1,24 +1,29 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class MrpBom(models.Model): _inherit = "mrp.bom" location_id = fields.Many2one( - related='picking_type_id.default_location_dest_id', - readonly=True, - store=True, + string='Location', + comodel_name='stock.location', ) + @api.onchange('picking_type_id') + def _onchange_picking_type_id(self): + if (self.picking_type_id and + self.picking_type_id.default_location_src_id): + self.location_id = self.picking_type_id.default_location_src_id + class MrpBomLine(models.Model): _inherit = "mrp.bom.line" location_id = fields.Many2one( - related='bom_id.picking_type_id.default_location_src_id', + related='bom_id.location_id', readonly=True, store=True, ) diff --git a/mrp_bom_location/report/bom_structure.py b/mrp_bom_location/report/bom_structure.py index 557203991..f8a2665ed 100644 --- a/mrp_bom_location/report/bom_structure.py +++ b/mrp_bom_location/report/bom_structure.py @@ -6,7 +6,7 @@ from odoo import api, models class BomStructureReport(models.AbstractModel): - _name = 'report.mrp.mrp_bom_structure_report' + _inherit = 'report.mrp.mrp_bom_structure_report' @staticmethod def _get_child_vals(record, level, qty, uom):