diff --git a/mrp_produce_uos/README.rst b/mrp_produce_uos/README.rst new file mode 100644 index 000000000..dff4db264 --- /dev/null +++ b/mrp_produce_uos/README.rst @@ -0,0 +1,49 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============== +MRP Produce UOS +=============== + +This module adds the field uos quantity to Product Produce wizard allowing the +user to use the uos quantity (instead of the standard uom) to specify the +quantity to be produced. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/95/8.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 smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Alex Comba + +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 http://odoo-community.org. diff --git a/mrp_produce_uos/__init__.py b/mrp_produce_uos/__init__.py new file mode 100644 index 000000000..e85d870df --- /dev/null +++ b/mrp_produce_uos/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models +from . import wizard diff --git a/mrp_produce_uos/__openerp__.py b/mrp_produce_uos/__openerp__.py new file mode 100644 index 000000000..e651b25d6 --- /dev/null +++ b/mrp_produce_uos/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + 'name': 'MRP Produce UOS', + 'version': '8.0.1.0.0', + 'category': 'Manufacturing', + 'author': "Agile Business Group, Odoo Community Association (OCA)", + 'website': 'http://www.agilebg.com', + 'license': 'AGPL-3', + 'depends': [ + 'mrp', + ], + 'data': [ + 'wizard/mrp_product_produce_view.xml', + ], + 'installable': True, +} diff --git a/mrp_produce_uos/i18n/it.po b/mrp_produce_uos/i18n/it.po new file mode 100644 index 000000000..cd2aa977d --- /dev/null +++ b/mrp_produce_uos/i18n/it.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_produce_uos +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-24 13:45+0000\n" +"PO-Revision-Date: 2015-09-24 15:45+0100\n" +"Last-Translator: Alex Comba \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: it\n" +"X-Generator: Poedit 1.7.5\n" + +#. module: mrp_produce_uos +#: model:ir.model,name:mrp_produce_uos.model_mrp_product_produce +msgid "Product Produce" +msgstr "Produci Prodotto" + +#. module: mrp_produce_uos +#: field:mrp.product.produce,product_uos_qty:0 +msgid "Select Quantity (UOS)" +msgstr "Seleziona la quantità (UOS)" diff --git a/mrp_produce_uos/i18n/mrp_produce_uos.pot b/mrp_produce_uos/i18n/mrp_produce_uos.pot new file mode 100644 index 000000000..8a807ee69 --- /dev/null +++ b/mrp_produce_uos/i18n/mrp_produce_uos.pot @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_produce_uos +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-24 13:44+0000\n" +"PO-Revision-Date: 2015-09-24 13:44+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: mrp_produce_uos +#: model:ir.model,name:mrp_produce_uos.model_mrp_product_produce +msgid "Product Produce" +msgstr "" + +#. module: mrp_produce_uos +#: field:mrp.product.produce,product_uos_qty:0 +msgid "Select Quantity (UOS)" +msgstr "" + diff --git a/mrp_produce_uos/models/__init__.py b/mrp_produce_uos/models/__init__.py new file mode 100644 index 000000000..18d1d6ff0 --- /dev/null +++ b/mrp_produce_uos/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import mrp_production diff --git a/mrp_produce_uos/models/mrp_production.py b/mrp_produce_uos/models/mrp_production.py new file mode 100644 index 000000000..dc851aa0d --- /dev/null +++ b/mrp_produce_uos/models/mrp_production.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import models, api + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + @api.model + def action_produce(self, production_id, production_qty, + production_mode, wiz=False): + res = super(MrpProduction, self).action_produce( + production_id, production_qty, production_mode, wiz) + + mrp_production = self.browse(production_id) + + for move in mrp_production.move_created_ids2: + product_uom_qty = move.product_uom_qty + p_qty = mrp_production.product_qty + p_uos_qty = mrp_production.product_uos_qty + product_uos_qty = p_uos_qty * (product_uom_qty / p_qty) + # I used sql to avoid + # https://github.com/odoo/odoo/blob/8.0/addons/stock/stock.py#L1980 + self.env.cr.execute( + 'UPDATE stock_move SET product_uos_qty = %s ' + 'WHERE id = %s', + (product_uos_qty, move.id) + ) + + return res diff --git a/mrp_produce_uos/static/description/icon.png b/mrp_produce_uos/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_produce_uos/static/description/icon.png differ diff --git a/mrp_produce_uos/tests/__init__.py b/mrp_produce_uos/tests/__init__.py new file mode 100644 index 000000000..6506de792 --- /dev/null +++ b/mrp_produce_uos/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_mrp_produce_uos diff --git a/mrp_produce_uos/tests/test_mrp_produce_uos.py b/mrp_produce_uos/tests/test_mrp_produce_uos.py new file mode 100644 index 000000000..0a7304306 --- /dev/null +++ b/mrp_produce_uos/tests/test_mrp_produce_uos.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp.tests.common import TransactionCase + + +class TestMrpProduceUos(TransactionCase): + + def setUp(self): + super(TestMrpProduceUos, self).setUp() + self.product_model = self.env['product.product'] + self.bom_model = self.env['mrp.bom'] + self.production_model = self.env['mrp.production'] + self.wizard_model = self.env['mrp.product.produce'] + + self.product_a = self.product_model.create({ + 'name': 'Product A', + 'list_price': 30, + 'uom_id': self.env.ref('product.product_uom_meter').id, + 'uom_po_id': self.env.ref('product.product_uom_meter').id, + 'uos_id': self.env.ref('product.product_uom_unit').id, + }) + + self.product_b = self.product_model.create({ + 'name': 'Product B', + 'standard_price': 10, + }) + + self.bom = self.bom_model.create({ + 'product_tmpl_id': self.product_a.product_tmpl_id.id, + 'product_qty': 1, + 'product_uom': self.env.ref('product.product_uom_meter').id, + 'bom_line_ids': [ + (0, 0, { + 'product_id': self.product_b.id, + 'product_qty': 2, + }), + ], + }) + + def prepare_production(self): + self.production = self.production_model.create({ + 'product_id': self.product_a.id, + 'product_qty': 0.5, + 'product_uos_qty': 1, + 'bom_id': self.bom.id, + 'product_uom': self.product_a.uom_id.id, + 'product_uos': self.product_a.uos_id.id, + }) + self.wizard = self.wizard_model.with_context( + {'active_id': self.production.id}).create({ + 'product_id': self.product_a.id, + }) + + def produce(self): + self.production.action_confirm() + self.wizard.product_uos_qty = 0.5 + self.wizard._onchange_product_uos_qty() + self.production_model.action_produce( + self.production.id, self.wizard.product_qty, + 'consume_produce', self.wizard) + self.production.refresh() + self.assertEqual( + len(self.production.move_created_ids2), 1) + self.move_produced = self.production.move_created_ids2[0] + + self.assertEqual(self.move_produced.product_uom_qty, 0.25) + self.assertEqual(self.move_produced.product_uos_qty, 0.5) + + self.assertEqual( + len(self.production.move_created_ids), 1) + self.move_to_produce = self.production.move_created_ids[0] + + self.assertEqual(self.move_to_produce.product_uom_qty, 0.25) + self.assertEqual(self.move_to_produce.product_uos_qty, 0.5) + + def test_action_produce(self): + self.prepare_production() + self.produce() diff --git a/mrp_produce_uos/wizard/__init__.py b/mrp_produce_uos/wizard/__init__.py new file mode 100644 index 000000000..99c176413 --- /dev/null +++ b/mrp_produce_uos/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import mrp_product_produce diff --git a/mrp_produce_uos/wizard/mrp_product_produce.py b/mrp_produce_uos/wizard/mrp_product_produce.py new file mode 100644 index 000000000..1c783e3c9 --- /dev/null +++ b/mrp_produce_uos/wizard/mrp_product_produce.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alex Comba - Agile Business Group +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, fields, models +import openerp.addons.decimal_precision as dp + + +class MrpProductProduce(models.TransientModel): + _inherit = 'mrp.product.produce' + + @api.model + def _default_product_uos_qty(self): + mrp_production = self.env['mrp.production'].browse( + self.env.context['active_id']) + product_qty = self._get_product_qty() + p_qty = mrp_production.product_qty + p_uos_qty = mrp_production.product_uos_qty + product_uos_qty = p_uos_qty * (product_qty / p_qty) + return product_uos_qty + + product_uos_qty = fields.Float( + 'Select Quantity (UOS)', + digits=dp.get_precision('Product Unit of Measure'), + default=_default_product_uos_qty,) + + @api.onchange('product_uos_qty') + def _onchange_product_uos_qty(self): + mrp_production = self.env['mrp.production'].browse( + self.env.context['active_id']) + p_qty = mrp_production.product_qty + p_uos_qty = mrp_production.product_uos_qty + self.product_qty = p_qty * (self.product_uos_qty / p_uos_qty) diff --git a/mrp_produce_uos/wizard/mrp_product_produce_view.xml b/mrp_produce_uos/wizard/mrp_product_produce_view.xml new file mode 100644 index 000000000..7368333ae --- /dev/null +++ b/mrp_produce_uos/wizard/mrp_product_produce_view.xml @@ -0,0 +1,17 @@ + + + + + + mrp.product.produce.view.form + mrp.product.produce + + + + + + + + + +