From 30ea0e41d8c2b18999bb642044cb7a180ffbac9c Mon Sep 17 00:00:00 2001 From: mpanarin Date: Mon, 12 Feb 2018 18:44:35 +0200 Subject: [PATCH] [MIG] mrp_bom_location: Migration to Odoo 11 --- mrp_bom_location/README.rst | 4 +- mrp_bom_location/__init__.py | 1 - .../{__openerp__.py => __manifest__.py} | 6 +- mrp_bom_location/models/__init__.py | 1 - mrp_bom_location/models/mrp_bom.py | 17 ++--- mrp_bom_location/report/__init__.py | 1 - mrp_bom_location/report/bom_structure.py | 73 ++++++++++++------- mrp_bom_location/views/mrp_view.xml | 17 +---- .../views/report_mrpbomstructure.xml | 2 +- 9 files changed, 61 insertions(+), 61 deletions(-) rename mrp_bom_location/{__openerp__.py => __manifest__.py} (80%) diff --git a/mrp_bom_location/README.rst b/mrp_bom_location/README.rst index b972ade39..ba1c833f5 100644 --- a/mrp_bom_location/README.rst +++ b/mrp_bom_location/README.rst @@ -1,4 +1,4 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: https://www.gnu.org/licenses/agpl :alt: License: AGPL-3 @@ -23,7 +23,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/129/9.0 + :target: https://runbot.odoo-community.org/runbot/129/11.0 Bug Tracker =========== diff --git a/mrp_bom_location/__init__.py b/mrp_bom_location/__init__.py index e24555ed0..347b23ce7 100644 --- a/mrp_bom_location/__init__.py +++ b/mrp_bom_location/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/mrp_bom_location/__openerp__.py b/mrp_bom_location/__manifest__.py similarity index 80% rename from mrp_bom_location/__openerp__.py rename to mrp_bom_location/__manifest__.py index ca1e0277f..6aa0b696b 100644 --- a/mrp_bom_location/__openerp__.py +++ b/mrp_bom_location/__manifest__.py @@ -1,16 +1,14 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "MRP BOM Location", "summary": "Adds location field to Bill of Materials and its components.", - "version": "9.0.1.0.0", + "version": "11.0.1.0.0", "category": "Manufacture", - "website": "https://odoo-community.org/", + "website": "https://github.com/OCA/manufacture", "author": "Eficent, Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, - "installable": True, "depends": [ "mrp", ], diff --git a/mrp_bom_location/models/__init__.py b/mrp_bom_location/models/__init__.py index c381246d4..a06bc71a4 100644 --- a/mrp_bom_location/models/__init__.py +++ b/mrp_bom_location/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/mrp_bom_location/models/mrp_bom.py b/mrp_bom_location/models/mrp_bom.py index 50f317648..3a2f742c8 100644 --- a/mrp_bom_location/models/mrp_bom.py +++ b/mrp_bom_location/models/mrp_bom.py @@ -1,23 +1,22 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import fields, models +from odoo import fields, models class MrpBom(models.Model): _inherit = "mrp.bom" location_id = fields.Many2one( - comodel_name="stock.location", string="Location", - help="Set the preferred location for this BOM.", - domain=[('usage', '=', 'internal')]) + related='picking_type_id.default_location_dest_id', + store=True, + ) -class MrpBom(models.Model): +class MrpBomLine(models.Model): _inherit = "mrp.bom.line" location_id = fields.Many2one( - comodel_name="stock.location", string="Location", - help="Location which it is expected to get the products from.", - domain=[('usage', '=', 'internal')]) + related='bom_id.picking_type_id.default_location_src_id', + store=True, + ) diff --git a/mrp_bom_location/report/__init__.py b/mrp_bom_location/report/__init__.py index 55d26865b..9956baed8 100644 --- a/mrp_bom_location/report/__init__.py +++ b/mrp_bom_location/report/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/mrp_bom_location/report/bom_structure.py b/mrp_bom_location/report/bom_structure.py index 97b729467..557203991 100644 --- a/mrp_bom_location/report/bom_structure.py +++ b/mrp_bom_location/report/bom_structure.py @@ -1,47 +1,64 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp.osv import osv -from openerp.report import report_sxw +from odoo import api, models -class bom_structure(report_sxw.rml_parse): - def __init__(self, cr, uid, name, context): - super(bom_structure, self).__init__(cr, uid, name, context=context) - self.localcontext.update({ - 'get_children': self.get_children, - }) +class BomStructureReport(models.AbstractModel): + _name = 'report.mrp.mrp_bom_structure_report' - def get_children(self, record, level=0): + @staticmethod + def _get_child_vals(record, level, qty, uom): + child = { + 'pname': record.product_id.name_get()[0][1], + 'pcode': record.product_id.default_code, + 'puom': record.product_uom_id, + 'uname': record.product_uom_id.name, + 'level': level, + 'code': record.bom_id.code, + 'location_name': record.location_id.complete_name or '', + } + qty_per_bom = record.bom_id.product_qty + if uom: + if uom != record.bom_id.product_uom_id: + qty = uom._compute_quantity(qty, record.bom_id.product_uom_id) + child['pqty'] = (record.product_qty * qty) / qty_per_bom + else: + # for the first case, the ponderation is right + child['pqty'] = (record.product_qty * qty) + return child + + def get_children(self, records, level=0): result = [] - def _get_rec(record, level, qty=1.0): - for l in record: - res = {} - res['pname'] = l.product_id.name_get()[0][1] - res['pcode'] = l.product_id.default_code - res['pqty'] = l.product_qty * qty - res['uname'] = l.product_uom.name - res['level'] = level - res['code'] = l.bom_id.code - res['location_name'] = l.location_id.complete_name or '' - result.append(res) + def _get_children_recursive(records, level, qty=1.0, uom=None): + for l in records: + child = self._get_child_vals(l, level, qty, uom) + result.append(child) if l.child_line_ids: if level < 6: level += 1 - _get_rec(l.child_line_ids, level, qty=res['pqty']) + _get_children_recursive( + l.child_line_ids, + level, + qty=child['pqty'], + uom=child['puom'] + ) if level > 0 and level < 6: level -= 1 return result - children = _get_rec(record, level) + children = _get_children_recursive(records, level) return children - -class report_mrpbomstructure_location(osv.AbstractModel): - _inherit = 'report.mrp.report_mrpbomstructure' - _template = 'mrp.report_mrpbomstructure' - _wrapped_report_class = bom_structure + @api.multi + def get_report_values(self, docids, data=None): + return { + 'doc_ids': docids, + 'doc_model': 'mrp.bom', + 'docs': self.env['mrp.bom'].browse(docids), + 'get_children': self.get_children, + 'data': data, + } diff --git a/mrp_bom_location/views/mrp_view.xml b/mrp_bom_location/views/mrp_view.xml index 49d1b8a3c..7cec665a4 100644 --- a/mrp_bom_location/views/mrp_view.xml +++ b/mrp_bom_location/views/mrp_view.xml @@ -8,9 +8,9 @@ mrp.bom - + @@ -47,18 +47,7 @@ mrp.bom.line - - - - - - - - mrp.bom.tree - mrp_bom_location - mrp.bom.line - - - + diff --git a/mrp_bom_location/views/report_mrpbomstructure.xml b/mrp_bom_location/views/report_mrpbomstructure.xml index b4ee8cda7..be2a75a61 100644 --- a/mrp_bom_location/views/report_mrpbomstructure.xml +++ b/mrp_bom_location/views/report_mrpbomstructure.xml @@ -1,7 +1,7 @@