diff --git a/product_quick_bom/README.rst b/product_quick_bom/README.rst index 5dac978a2..2697b28e9 100644 --- a/product_quick_bom/README.rst +++ b/product_quick_bom/README.rst @@ -2,24 +2,14 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -============== -{module_title} -============== +================= +product_quick_bom +================= This module was written to create quickly the bom for your product. Indeed in the product form you now have a new tab "bom" that give you the posibility to add the bom line directly here -Installation -============ - -To install this module, you just need to install it - -Configuration -============= - -No configuration is required - Usage ===== @@ -30,7 +20,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/{repo_id}/{branch} + :target: https://runbot.odoo-community.org/runbot/manufacture/10.0 .. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt .. branch is "8.0" for example @@ -39,18 +29,14 @@ For further information, please visit: * https://www.odoo.com/forum/help-1 -Known issues / Roadmap -====================== - -* ... Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 smashing it by providing a detailed and welcomed feedback -`here `_. +`here `_. Credits diff --git a/product_quick_bom/__init__.py b/product_quick_bom/__init__.py index ed8e79d96..e55d597f7 100644 --- a/product_quick_bom/__init__.py +++ b/product_quick_bom/__init__.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP # Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import product from . import bom diff --git a/product_quick_bom/__manifest__.py b/product_quick_bom/__manifest__.py new file mode 100644 index 000000000..5d7f04e59 --- /dev/null +++ b/product_quick_bom/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Product Quick Bom", + "summary": "Create the bom directly from the product", + "version": "10.0.1.0.0", + "category": "mrp", + "website": "https://odoo-community.org/", + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mrp", + ], + "data": [ + "product_view.xml", + ], + +} diff --git a/product_quick_bom/__openerp__.py b/product_quick_bom/__openerp__.py deleted file mode 100644 index b82ce6937..000000000 --- a/product_quick_bom/__openerp__.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP -# Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### - -{ - "name": "Product Quick Bom", - "summary": "Create the bom directly from the product", - "version": "8.0.1.0.0", - "category": "mrp", - "website": "https://odoo-community.org/", - "author": "Akretion, Odoo Community Association (OCA)", - "license": "AGPL-3", - "application": False, - "installable": True, - "external_dependencies": { - "python": [], - "bin": [], - }, - "depends": [ - "mrp", - ], - "data": [ - "product_view.xml", - ], - "demo": [ - ], -} diff --git a/product_quick_bom/bom.py b/product_quick_bom/bom.py index d333c187e..9e3313ab2 100644 --- a/product_quick_bom/bom.py +++ b/product_quick_bom/bom.py @@ -1,28 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP # Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api -from collections import defaultdict -from openerp.exceptions import Warning as UserError +from odoo import fields, models, _ class MrpBom(models.Model): @@ -31,7 +11,7 @@ class MrpBom(models.Model): _sql_constraint = ( 'uniq_product_template', 'uniq(product_tmpl_id)', - 'You can only have one Bom per product template', + _('You can only have one Bom per product template'), ) @@ -39,6 +19,7 @@ class MrpBomLine(models.Model): _inherit = 'mrp.bom.line' product_tmpl_id = fields.Many2one( - 'product.template', + comodel_name='product.template', related='bom_id.product_tmpl_id', + readonly=True, store=True) diff --git a/product_quick_bom/i18n/fr.po b/product_quick_bom/i18n/fr.po index 2687df31c..06e34065b 100644 --- a/product_quick_bom/i18n/fr.po +++ b/product_quick_bom/i18n/fr.po @@ -32,7 +32,7 @@ msgstr "Composant" #. module: product_quick_bom #: help:product.template,bom_line_ids:0 -msgid "If you product is manufactured you can selecthere the componant to product them" +msgid "If your product is manufactured you can select here the component to produce them" msgstr "Si votre produit est fabriqué vous pouvez définir les composants ici" #. module: product_quick_bom diff --git a/product_quick_bom/i18n/product_quick_bom.pot b/product_quick_bom/i18n/product_quick_bom.pot deleted file mode 100644 index 6e228f84a..000000000 --- a/product_quick_bom/i18n/product_quick_bom.pot +++ /dev/null @@ -1,42 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * product_quick_bom -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-09-13 16:25+0000\n" -"PO-Revision-Date: 2015-09-13 16:25+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: product_quick_bom -#: model:ir.model,name:product_quick_bom.model_mrp_bom -msgid "Bill of Material" -msgstr "" - -#. module: product_quick_bom -#: field:product.template,bom_line_ids:0 -msgid "Bom Line" -msgstr "" - -#. module: product_quick_bom -#: view:product.template:product_quick_bom.product_template_form_view -msgid "Bom line" -msgstr "" - -#. module: product_quick_bom -#: help:product.template,bom_line_ids:0 -msgid "If you product is manufactured you can selecthere the componant to product them" -msgstr "" - -#. module: product_quick_bom -#: model:ir.model,name:product_quick_bom.model_product_template -msgid "Product Template" -msgstr "" - diff --git a/product_quick_bom/product.py b/product_quick_bom/product.py index 7040315b6..1517bcec9 100644 --- a/product_quick_bom/product.py +++ b/product_quick_bom/product.py @@ -1,39 +1,19 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP # Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api -from collections import defaultdict -from openerp.exceptions import Warning as UserError +from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = 'product.template' bom_line_ids = fields.One2many( - 'mrp.bom.line', - 'product_tmpl_id', + comodel_name='mrp.bom.line', + inverse_name='product_tmpl_id', string='Bom Line', - help='If you product is manufactured you can select' - 'here the componant to product them') + help='If your product is manufactured you can select ' + 'here the component to produce them') @api.model def _extract_bom_line(self, vals): @@ -41,17 +21,19 @@ class ProductTemplate(models.Model): @api.multi def _prepare_bom_vals(self, vals): + self.ensure_one() return { 'product_tmpl_id': self.id, 'bom_line_ids': vals, } - @api.one + @api.multi def _process_bom_vals(self, vals): - if self.bom_ids: - self.bom_ids[0].write({'bom_line_ids': vals}) - else: - bom = self.env['mrp.bom'].create(self._prepare_bom_vals(vals)) + for record in self: + if record.bom_ids: + record.bom_ids[0].write({'bom_line_ids': vals}) + else: + record.env['mrp.bom'].create(self._prepare_bom_vals(vals)) @api.model def create(self, vals): @@ -63,10 +45,16 @@ class ProductTemplate(models.Model): @api.multi def write(self, vals): + """ default_type is in product and bom so _context ovewrite the default + value for bom with typ:'product' need to becarefull + """ bom_vals = self._extract_bom_line(vals) res = super(ProductTemplate, self).write(vals) if bom_vals: - self._process_bom_vals(bom_vals) + ctx = self._context.copy() + ctx.pop('default_type', None) + self.with_context(ctx)._process_bom_vals(bom_vals) + return res @api.multi diff --git a/product_quick_bom/product_view.xml b/product_quick_bom/product_view.xml index 0a996070b..804c1267c 100644 --- a/product_quick_bom/product_view.xml +++ b/product_quick_bom/product_view.xml @@ -1,13 +1,11 @@ - - - + product.template - + @@ -19,6 +17,4 @@ - - - + diff --git a/product_quick_bom/static/description/index.html b/product_quick_bom/static/description/index.html deleted file mode 100644 index 27f067420..000000000 --- a/product_quick_bom/static/description/index.html +++ /dev/null @@ -1,124 +0,0 @@ -
-
-
-

Module name

-

This module was written to extend the functionality of ... to support ... and allow you to ...

-
-
-
- -
-
-
-

Installation

-
-
-

To install this module, you need to: -

    -
  • ...
  • -
-

-
-
-
- - - -
-
-
-
- -
-
-
-

Configuration

-
-
-

To configure this module, you need to: -

    -
  • ...
  • -
-

-
-
-
- - - -
-
-
-
- -
-
-
-

Usage

-
-
-

To use this module, you need to: -

    -
  • ...
  • -
-

-

For further information, please visit: -

-

-
-
-
- - - -
-
-
-
- -
-
-
-

Known issues / Roadmap

-
-
-

-

    -
  • ...
  • -
-

-
-
-
- - - -
-
-
-
- -
-
-
-

Credits

-
-
-

Contributors

- -
-
-

Maintainer

-

- 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 http://odoo-community.org.
- -

-
-
-
diff --git a/product_quick_bom/tests/__init__.py b/product_quick_bom/tests/__init__.py new file mode 100644 index 000000000..161d59021 --- /dev/null +++ b/product_quick_bom/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_quick_bom \ No newline at end of file diff --git a/product_quick_bom/tests/test_quick_bom.py b/product_quick_bom/tests/test_quick_bom.py new file mode 100644 index 000000000..101fa367d --- /dev/null +++ b/product_quick_bom/tests/test_quick_bom.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +import logging +_logger = logging.getLogger(__name__) + + +class TestQuickBom(TransactionCase): + + def setUp(self): + super(TestQuickBom, self).setUp() + self.computer = self.env.ref( + 'product.product_product_5_product_template') + self.ram = self.env.ref('product.product_product_13_product_template') + self.hard_drive = self.env.ref( + 'product.product_product_17_product_template') + self.cpu = self.env.ref('product.product_product_22_product_template') + + def test_create_bom(self): + self.computer.write({'bom_line_ids': [ + (0, 0, {'product_id': self.ram.id, 'product_qty': 2, }), + (0, 0, {'product_id': self.hard_drive.id, 'product_qty': 2, }), + (0, 0, {'product_id': self.cpu.id, 'product_qty': 1, })]}) + bom = self.computer.bom_ids + self.assertEqual(self.computer.id, bom.product_tmpl_id.id) + self.assertEqual(bom.bom_line_ids[0].product_id.id, + self.ram.id) + self.assertEqual(bom.bom_line_ids[0].product_qty, 2) + self.assertEqual(bom.bom_line_ids[1].product_id.id, + self.hard_drive.id) + self.assertEqual(bom.bom_line_ids[1].product_qty, 2) + self.assertEqual(bom.bom_line_ids[2].product_id.id, + self.cpu.id) + self.assertEqual(bom.bom_line_ids[2].product_qty, 1) + + def test_read_bom(self): + + bom = self.env['mrp.bom'].create({ + 'type': 'normal', + 'product_tmpl_id': self.computer.id}) + bomline1 = self.env['mrp.bom.line'].create({ + 'product_id': self.ram.id, + 'product_qty': 2, + 'bom_id': bom.id, + }) + bomline2 = self.env['mrp.bom.line'].create({ + 'product_id': self.hard_drive.id, + 'product_qty': 2, + 'bom_id': bom.id, + }) + bomline3 = self.env['mrp.bom.line'].create({ + 'product_id': self.cpu.id, + 'product_qty': 1, + 'bom_id': bom.id, + }) + + self.assertTrue(bomline1 in self.computer.bom_line_ids) + self.assertTrue(bomline2 in self.computer.bom_line_ids) + self.assertTrue(bomline3 in self.computer.bom_line_ids)