diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 97d65889fe1..667868846e4 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,5 +1,6 @@ # list the OCA project dependencies, one per line # add a github url if you need a forked version +product-attribute purchase-workflow web server-ux diff --git a/stock_secondary_unit/README.rst b/stock_secondary_unit/README.rst new file mode 100644 index 00000000000..c97b74b79e3 --- /dev/null +++ b/stock_secondary_unit/README.rst @@ -0,0 +1,87 @@ +==================== +Stock Secondary Unit +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/11.0/stock_secondary_unit + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-11-0/stock-logistics-warehouse-11-0-stock_secondary_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of stock module to allow define +other units with their conversion factor. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module you need to: + +#. Go to a *Product > General Information tab*. +#. Create any record in "Secondary unit of measure". +#. Set the conversion factor. +#. Go to *Inventory tab* and set a second unit of measure. +#. Push button 'Quantity on hand' and set quantities in stock for this product. +#. Go to product list and you can see the secondary unit value. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Carlos Dauden +* Sergio Teruel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_secondary_unit/__init__.py b/stock_secondary_unit/__init__.py new file mode 100644 index 00000000000..3275ac2adf3 --- /dev/null +++ b/stock_secondary_unit/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/stock_secondary_unit/__manifest__.py b/stock_secondary_unit/__manifest__.py new file mode 100644 index 00000000000..5e0d2718bfe --- /dev/null +++ b/stock_secondary_unit/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Stock Secondary Unit', + 'summary': 'Get product quantities in a secondary unit', + 'version': '11.0.1.0.0', + 'development_status': 'Beta', + 'category': 'stock', + 'website': 'https://github.com/OCA/stock-logistics-warehouse', + 'author': 'Tecnativa, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'sale_stock', + 'product_secondary_unit', + ], + 'data': [ + 'views/product_views.xml', + 'views/stock_move_views.xml', + 'views/stock_picking_views.xml', + 'report/report_deliveryslip.xml', + ], +} diff --git a/stock_secondary_unit/i18n/es.po b/stock_secondary_unit/i18n/es.po new file mode 100644 index 00000000000..a67559a4efc --- /dev/null +++ b/stock_secondary_unit/i18n/es.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-09-11 06:27+0000\n" +"PO-Revision-Date: 2018-09-11 08:28+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: stock_secondary_unit +#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: stock_secondary_unit +#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_id +msgid "ID" +msgstr "ID" + +#. module: stock_secondary_unit +#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit___last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: stock_secondary_unit +#: model:ir.ui.view,arch_db:stock_secondary_unit.product_form_view_procurement_button +#: model:ir.ui.view,arch_db:stock_secondary_unit.product_template_form_view_procurement_button +msgid "On Hand (2unit)" +msgstr "A mano (2Ud.)" + +#. module: stock_secondary_unit +#: model:ir.model,name:stock_secondary_unit.model_product_product +msgid "Product" +msgstr "Producto" + +#. module: stock_secondary_unit +#: model:ir.model,name:stock_secondary_unit.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: stock_secondary_unit +#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_product_secondary_unit_qty_available +#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_template_secondary_unit_qty_available +#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_secondary_unit_qty_available +msgid "Quantity On Hand (2Unit)" +msgstr "Cantidad a mano (2Ud.)" + +#. module: stock_secondary_unit +#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_product_stock_secondary_uom_id +#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_template_stock_secondary_uom_id +msgid "Second unit for inventory" +msgstr "Segunda unidad de medida para inventario" + +#. module: stock_secondary_unit +#: model:ir.ui.view,arch_db:stock_secondary_unit.view_template_property_form +msgid "Secondary unit" +msgstr "Unidad Secundaria" + +#. module: stock_secondary_unit +#: model:ir.model,name:stock_secondary_unit.model_stock_product_secondary_unit +msgid "stock.product.secondary.unit" +msgstr "" + +#~ msgid "Second Unit Quantity On Hand" +#~ msgstr "Segunda unidad de medida por defecto" diff --git a/stock_secondary_unit/models/__init__.py b/stock_secondary_unit/models/__init__.py new file mode 100644 index 00000000000..e8654048872 --- /dev/null +++ b/stock_secondary_unit/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import procurement_rule +from . import product +from . import stock_move diff --git a/stock_secondary_unit/models/procurement_rule.py b/stock_secondary_unit/models/procurement_rule.py new file mode 100644 index 00000000000..1d6ec8133fd --- /dev/null +++ b/stock_secondary_unit/models/procurement_rule.py @@ -0,0 +1,23 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class ProcurementRule(models.Model): + _inherit = 'procurement.rule' + + def _get_stock_move_values(self, product_id, product_qty, product_uom, + location_id, name, origin, values, group_id): + res = super(ProcurementRule, self)._get_stock_move_values( + product_id, product_qty, product_uom, location_id, name, origin, + values, group_id + ) + if values.get('sale_line_id', False): + sale_line = self.env['sale.order.line'].browse( + values['sale_line_id']) + if sale_line.secondary_uom_id: + res.update({ + 'secondary_uom_id': sale_line.secondary_uom_id.id, + 'secondary_uom_qty': sale_line.secondary_uom_qty, + }) + return res diff --git a/stock_secondary_unit/models/product.py b/stock_secondary_unit/models/product.py new file mode 100644 index 00000000000..49efefb039f --- /dev/null +++ b/stock_secondary_unit/models/product.py @@ -0,0 +1,45 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models +from odoo.addons import decimal_precision as dp +from odoo.tools.float_utils import float_round + + +class StockProductSecondaryUnit(models.AbstractModel): + _name = 'stock.product.secondary.unit' + + secondary_unit_qty_available = fields.Float( + string='Quantity On Hand (2Unit)', + compute='_compute_secondary_unit_qty_available', + digits=dp.get_precision('Product Unit of Measure'), + ) + + def _compute_secondary_unit_qty_available(self): + for product in self.filtered('stock_secondary_uom_id'): + qty = product.qty_available / ( + product.stock_secondary_uom_id.factor or 1.0) + product.secondary_unit_qty_available = float_round( + qty, precision_rounding=product.uom_id.rounding) + + +class ProductTemplate(models.Model): + _inherit = ['product.template', 'stock.product.secondary.unit'] + _name = 'product.template' + + stock_secondary_uom_id = fields.Many2one( + comodel_name='product.secondary.unit', + string='Second unit for inventory', + ) + + def _compute_quantities(self): + super()._compute_quantities() + self._compute_secondary_unit_qty_available() + + +class ProductProduct(models.Model): + _inherit = ['product.product', 'stock.product.secondary.unit'] + _name = 'product.product' + + def _compute_quantities(self): + super()._compute_quantities() + self._compute_secondary_unit_qty_available() diff --git a/stock_secondary_unit/models/stock_move.py b/stock_secondary_unit/models/stock_move.py new file mode 100644 index 00000000000..dcb5d615622 --- /dev/null +++ b/stock_secondary_unit/models/stock_move.py @@ -0,0 +1,51 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.addons import decimal_precision as dp +from odoo.tools.float_utils import float_round + + +class StockSecondaryUnitMixin(models.AbstractModel): + _name = 'stock.secondary.unit.mixin' + + secondary_uom_id = fields.Many2one( + comodel_name='product.secondary.unit', + string='Second unit', + ) + secondary_uom_qty = fields.Float( + string='Secondary Qty', + digits=dp.get_precision('Product Unit of Measure'), + ) + + +class StockMove(models.Model): + _inherit = ['stock.move', 'stock.secondary.unit.mixin'] + _name = 'stock.move' + + def _merge_moves_fields(self): + res = super(StockMove, self)._merge_moves_fields() + res['secondary_uom_qty'] = self[-1:].secondary_uom_qty + return res + + +class StockMoveLine(models.Model): + _inherit = ['stock.move.line', 'stock.secondary.unit.mixin'] + _name = 'stock.move.line' + + @api.model + def create(self, vals): + move = self.env['stock.move'].browse(vals['move_id']) + if move.secondary_uom_id: + uom = self.env['product.uom'].browse(vals['product_uom_id']) + factor = move.secondary_uom_id.factor * uom.factor + move_line_qty = vals.get( + 'product_uom_qty', vals.get('qty_done', 0.0)) + qty = float_round( + move_line_qty / (factor or 1.0), + precision_rounding=move.secondary_uom_id.uom_id.factor + ) + vals.update({ + 'secondary_uom_qty': qty, + 'secondary_uom_id': move.secondary_uom_id.id, + }) + return super().create(vals) diff --git a/stock_secondary_unit/readme/CONTRIBUTORS.rst b/stock_secondary_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..b919cb776aa --- /dev/null +++ b/stock_secondary_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Carlos Dauden +* Sergio Teruel diff --git a/stock_secondary_unit/readme/DESCRIPTION.rst b/stock_secondary_unit/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..ce69e8533ca --- /dev/null +++ b/stock_secondary_unit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of stock module to allow define +other units with their conversion factor. diff --git a/stock_secondary_unit/readme/USAGE.rst b/stock_secondary_unit/readme/USAGE.rst new file mode 100644 index 00000000000..4d189ae535a --- /dev/null +++ b/stock_secondary_unit/readme/USAGE.rst @@ -0,0 +1,8 @@ +To use this module you need to: + +#. Go to a *Product > General Information tab*. +#. Create any record in "Secondary unit of measure". +#. Set the conversion factor. +#. Go to *Inventory tab* and set a second unit of measure. +#. Push button 'Quantity on hand' and set quantities in stock for this product. +#. Go to product list and you can see the secondary unit value. diff --git a/stock_secondary_unit/report/report_deliveryslip.xml b/stock_secondary_unit/report/report_deliveryslip.xml new file mode 100755 index 00000000000..b7c7ee70036 --- /dev/null +++ b/stock_secondary_unit/report/report_deliveryslip.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/stock_secondary_unit/static/description/icon.png b/stock_secondary_unit/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/stock_secondary_unit/static/description/icon.png differ diff --git a/stock_secondary_unit/tests/__init__.py b/stock_secondary_unit/tests/__init__.py new file mode 100644 index 00000000000..38c91ad2e9f --- /dev/null +++ b/stock_secondary_unit/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_stock_secondary_unit diff --git a/stock_secondary_unit/tests/test_stock_secondary_unit.py b/stock_secondary_unit/tests/test_stock_secondary_unit.py new file mode 100644 index 00000000000..4dfd737d669 --- /dev/null +++ b/stock_secondary_unit/tests/test_stock_secondary_unit.py @@ -0,0 +1,85 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import SavepointCase + + +class TestProductSecondaryUnit(SavepointCase): + at_install = False + post_install = True + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse = cls.env.ref('stock.warehouse0') + cls.product_uom_kg = cls.env.ref('product.product_uom_kgm') + cls.product_uom_unit = cls.env.ref('product.product_uom_unit') + ProductAttribute = cls.env['product.attribute'] + ProductAttributeValue = cls.env['product.attribute.value'] + cls.attribute_color = ProductAttribute.create({'name': 'test_color'}) + cls.attribute_value_white = ProductAttributeValue.create({ + 'name': 'test_white', + 'attribute_id': cls.attribute_color.id, + }) + cls.attribute_value_black = ProductAttributeValue.create({ + 'name': 'test_black', + 'attribute_id': cls.attribute_color.id, + }) + Product = cls.env['product.product'] + cls.product_template = cls.env['product.template'].create({ + 'name': 'test', + 'uom_id': cls.product_uom_kg.id, + 'uom_po_id': cls.product_uom_kg.id, + 'type': 'product', + 'secondary_uom_ids': [ + (0, 0, { + 'code': 'A', + 'name': 'unit-700', + 'uom_id': cls.product_uom_unit.id, + 'factor': 0.5, + }), + (0, 0, { + 'code': 'B', + 'name': 'unit-900', + 'uom_id': cls.product_uom_unit.id, + 'factor': 0.9, + }), + ], + 'attribute_line_ids': [(0, 0, { + 'attribute_id': cls.attribute_color.id, + })], + }) + cls.product_white = Product.create({ + 'product_tmpl_id': cls.product_template.id, + 'attribute_value_ids': [(6, 0, [cls.attribute_value_white.id])], + }) + cls.product_black = Product.create({ + 'product_tmpl_id': cls.product_template.id, + 'attribute_value_ids': [(6, 0, [cls.attribute_value_black.id])], + }) + secondary_unit = cls.env['product.secondary.unit'].search([ + ('product_tmpl_id', '=', cls.product_template.id), + ], limit=1) + cls.product_template.write({ + 'sale_secondary_uom_id': secondary_unit.id, + 'stock_secondary_uom_id': secondary_unit.id, + }) + StockQuant = cls.env['stock.quant'] + cls.quant_white = StockQuant.create({ + 'product_id': cls.product_white.id, + 'location_id': cls.warehouse.lot_stock_id.id, + 'quantity': 10.0, + }) + cls.quant_black = StockQuant.create({ + 'product_id': cls.product_black.id, + 'location_id': cls.warehouse.lot_stock_id.id, + 'quantity': 10.0, + }) + + def test_stock_secondary_unit_template(self): + self.assertEqual( + self.product_template.secondary_unit_qty_available, 40.0) + + def test_stock_secondary_unit_variant(self): + for variant in self.product_template.product_variant_ids.filtered( + 'attribute_value_ids'): + self.assertEqual(variant.secondary_unit_qty_available, 20) diff --git a/stock_secondary_unit/views/product_views.xml b/stock_secondary_unit/views/product_views.xml new file mode 100755 index 00000000000..8b14bc6da40 --- /dev/null +++ b/stock_secondary_unit/views/product_views.xml @@ -0,0 +1,86 @@ + + + + + + Product template Secondary Unit + product.template + + + + + + + + + + + + + product.template + + + + + + + + + + + product.product + + + + + + + + + + + product.template + + + + + + + + + + + + product.product + + + + + + + + + + + diff --git a/stock_secondary_unit/views/stock_move_views.xml b/stock_secondary_unit/views/stock_move_views.xml new file mode 100755 index 00000000000..c130d219bf1 --- /dev/null +++ b/stock_secondary_unit/views/stock_move_views.xml @@ -0,0 +1,21 @@ + + + + + + Stock Move Secondary Unit + stock.move.line + + + + + + + + + + + diff --git a/stock_secondary_unit/views/stock_picking_views.xml b/stock_secondary_unit/views/stock_picking_views.xml new file mode 100755 index 00000000000..0c099bff21e --- /dev/null +++ b/stock_secondary_unit/views/stock_picking_views.xml @@ -0,0 +1,27 @@ + + + + + + Stock Picking Secondary Unit + stock.picking + + + + + + + + + + + + + + +