diff --git a/mrp_bom_location/README.rst b/mrp_bom_location/README.rst new file mode 100644 index 000000000..4841dc04c --- /dev/null +++ b/mrp_bom_location/README.rst @@ -0,0 +1,65 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +================ +MRP BOM Location +================ + +This module adds the location field to the Bill of Materials and its +components. This may be useful to distinguish between different BoMs for the +same product or to highlight the preferred locations to fetch the +components from. + +The location appears in the BOM Structure Report. + + +Usage +===== + +To use this module, you need to: + +#. Go to *Manufacturing > Master Data > Bill of Materials*. + +.. 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/10.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Lois Rilo + +Do not contact contributors directly about support or help with technical +issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_bom_location/__init__.py b/mrp_bom_location/__init__.py new file mode 100644 index 000000000..f75d40a79 --- /dev/null +++ b/mrp_bom_location/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models +from . import report diff --git a/mrp_bom_location/__manifest__.py b/mrp_bom_location/__manifest__.py new file mode 100644 index 000000000..a4d7808ed --- /dev/null +++ b/mrp_bom_location/__manifest__.py @@ -0,0 +1,21 @@ +# -*- 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": "10.0.1.0.0", + "category": "Manufacture", + "website": "https://odoo-community.org/", + "author": "Eficent, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mrp", + ], + "data": [ + "views/mrp_view.xml", + "views/report_mrpbomstructure.xml", + ], +} diff --git a/mrp_bom_location/models/__init__.py b/mrp_bom_location/models/__init__.py new file mode 100644 index 000000000..fc89bf227 --- /dev/null +++ b/mrp_bom_location/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import mrp_bom diff --git a/mrp_bom_location/models/mrp_bom.py b/mrp_bom_location/models/mrp_bom.py new file mode 100644 index 000000000..1925b686a --- /dev/null +++ b/mrp_bom_location/models/mrp_bom.py @@ -0,0 +1,27 @@ +# -*- 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 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')], + ) + + +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')], + ) diff --git a/mrp_bom_location/report/__init__.py b/mrp_bom_location/report/__init__.py new file mode 100644 index 000000000..39674e504 --- /dev/null +++ b/mrp_bom_location/report/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import bom_structure diff --git a/mrp_bom_location/report/bom_structure.py b/mrp_bom_location/report/bom_structure.py new file mode 100644 index 000000000..539741af2 --- /dev/null +++ b/mrp_bom_location/report/bom_structure.py @@ -0,0 +1,47 @@ +# -*- 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 import models + + +class BomStructureReport(models.AbstractModel): + _inherit = 'report.mrp.report_mrpbomstructure' + + def get_children(self, record, level=0): + result = [] + + def _get_rec(record, level, qty=1.0, uom=False): + for l in record: + res = {} + res['pname'] = l.product_id.name_get()[0][1] + res['pcode'] = l.product_id.default_code + qty_per_bom = l.bom_id.product_qty + if uom: + if uom != l.bom_id.product_uom_id: + qty = uom._compute_quantity( + qty, l.bom_id.product_uom_id) + res['pqty'] = (l.product_qty * qty) / qty_per_bom + else: + # for the first case, the ponderation is right + res['pqty'] = (l.product_qty * qty) + res['puom'] = l.product_uom_id + res['uname'] = l.product_uom_id.name + res['level'] = level + res['code'] = l.bom_id.code + res['location_name'] = l.location_id.complete_name or '' + result.append(res) + if l.child_line_ids: + if level < 6: + level += 1 + _get_rec( + l.child_line_ids, level, + qty=res['pqty'], uom=res['puom']) + if 0 < level < 6: + level -= 1 + return result + + children = _get_rec(record, level) + + return children diff --git a/mrp_bom_location/static/description/icon.png b/mrp_bom_location/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_bom_location/static/description/icon.png differ diff --git a/mrp_bom_location/views/mrp_view.xml b/mrp_bom_location/views/mrp_view.xml new file mode 100644 index 000000000..186f08dae --- /dev/null +++ b/mrp_bom_location/views/mrp_view.xml @@ -0,0 +1,81 @@ + + + + + + mrp.bom.form - mrp_bom_location + mrp.bom + + + + + + + + + + + + + mrp.bom.tree - mrp_bom_location + mrp.bom + + + + + + + + + + mrp.bom.select - mrp_bom_location + mrp.bom + + + + + + + + + + + + + mrp.bom.component.tree - mrp_bom_location + mrp.bom.line + + + + + + + + + + mrp.bom.tree - mrp_bom_location + mrp.bom.line + + + + + + + + + + mrp.bom.line.select - mrp_bom_location + mrp.bom.line + + + + + + + + + + + + diff --git a/mrp_bom_location/views/report_mrpbomstructure.xml b/mrp_bom_location/views/report_mrpbomstructure.xml new file mode 100644 index 000000000..be2a75a61 --- /dev/null +++ b/mrp_bom_location/views/report_mrpbomstructure.xml @@ -0,0 +1,20 @@ + + + + diff --git a/setup/mrp_bom_location/odoo/__init__.py b/setup/mrp_bom_location/odoo/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/mrp_bom_location/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/mrp_bom_location/odoo/addons/__init__.py b/setup/mrp_bom_location/odoo/addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/mrp_bom_location/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/mrp_bom_location/odoo/addons/mrp_bom_location b/setup/mrp_bom_location/odoo/addons/mrp_bom_location new file mode 120000 index 000000000..92e74ddbd --- /dev/null +++ b/setup/mrp_bom_location/odoo/addons/mrp_bom_location @@ -0,0 +1 @@ +../../../../mrp_bom_location \ No newline at end of file diff --git a/setup/mrp_bom_location/setup.py b/setup/mrp_bom_location/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_bom_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)