diff --git a/product_variant_standard_price_update/README.rst b/product_variant_standard_price_update/README.rst new file mode 100644 index 000000000..80b230e22 --- /dev/null +++ b/product_variant_standard_price_update/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +===================================== +Product variant standard price update +===================================== + +This module extends the product variant feature to allow update standard price +in all variants from the product template form + +Installation +============ + +The module adds a button in template form for show a wizard to update the +price. + + +Usage +===== + +To use this module, you need to: + +#. Go to products and create one with variants. +#. Click on button "Update variants". +#. Check standard price in every variant of this product. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/137/9.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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + + +Contributors +------------ + +* Sergio Teruel + +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/product_variant_standard_price_update/__init__.py b/product_variant_standard_price_update/__init__.py new file mode 100644 index 000000000..f553d8ff3 --- /dev/null +++ b/product_variant_standard_price_update/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizards diff --git a/product_variant_standard_price_update/__openerp__.py b/product_variant_standard_price_update/__openerp__.py new file mode 100644 index 000000000..94603263f --- /dev/null +++ b/product_variant_standard_price_update/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Product Variant Standard Price Update", + "summary": "Update all variant standard price from the product template", + "version": "9.0.1.0.0", + "category": "Product", + "website": "http://www.tecnativa.com", + "author": "Tecnativa, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "product", + ], + "data": [ + "views/product_view.xml", + "wizards/product_variant_standard_price_update.xml", + ], +} diff --git a/product_variant_standard_price_update/i18n/es.po b/product_variant_standard_price_update/i18n/es.po new file mode 100644 index 000000000..6941764a5 --- /dev/null +++ b/product_variant_standard_price_update/i18n/es.po @@ -0,0 +1,119 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_standard_price_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-15 21:26+0000\n" +"PO-Revision-Date: 2016-12-15 22:31+0100\n" +"Last-Translator: Sergio Teruel \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: es_ES\n" +"X-Generator: Poedit 1.5.4\n" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.product_template_form_view_update_standard_price +msgid "Different cost price by variants. " +msgstr "Diferente coste por variante" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.wizard_view +msgid "Apply" +msgstr "Aplicar" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.wizard_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_standard_price +msgid "Cost Price" +msgstr "Precio coste" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_create_date +msgid "Created on" +msgstr "Creado en" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_display_name +msgid "Display Name" +msgstr "Nombre a mostrar" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_id +msgid "ID" +msgstr "ID (identificación)" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz___last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_write_uid +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_variant_standard_price_update_wiz_write_date +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: product_variant_standard_price_update +#: model:ir.model,name:product_variant_standard_price_update.model_product_template +msgid "Product Template" +msgstr "Plantilla producto" + +#. module: product_variant_standard_price_update +#: model:ir.model.fields,field_description:product_variant_standard_price_update.field_product_template_same_cost_variants +msgid "Same cost variants" +msgstr "Mismo coste para todas las variantes" + +#. module: product_variant_standard_price_update +#: code:addons/product_variant_standard_price_update/models/product.py:35 +#, python-format +msgid "Standard price update variants" +msgstr "Actualiza precios de coste de las variantes" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.product_template_form_view_update_standard_price +msgid "Update variant price" +msgstr "Actualiza coste" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.wizard_view +msgid "Update variant standard price" +msgstr "Actualiza el coste en las variantes" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.wizard_view +msgid "You can change cost price for all product variants.
" +msgstr "Puedes cambiar el precio de coste para todas las variantes" + +#. module: product_variant_standard_price_update +#: model:ir.ui.view,arch_db:product_variant_standard_price_update.wizard_view +msgid "or" +msgstr "o" + +#. module: product_variant_standard_price_update +#: model:ir.model,name:product_variant_standard_price_update.model_variant_price_update_wiz +#, fuzzy +msgid "variant.price.update.wiz" +msgstr "Actualiza los precios de las líneas" + +#. module: product_variant_standard_price_update +#: model:ir.model,name:product_variant_standard_price_update.model_variant_standard_price_update_wiz +msgid "variant.standard.price.update.wiz" +msgstr "" diff --git a/product_variant_standard_price_update/models/__init__.py b/product_variant_standard_price_update/models/__init__.py new file mode 100644 index 000000000..d4093de0f --- /dev/null +++ b/product_variant_standard_price_update/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import product diff --git a/product_variant_standard_price_update/models/product.py b/product_variant_standard_price_update/models/product.py new file mode 100644 index 000000000..df405f4b4 --- /dev/null +++ b/product_variant_standard_price_update/models/product.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import _, api, fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + @api.multi + def _compute_same_cost_variants(self): + for template in self: + cost = template.mapped('product_variant_ids.standard_price') + if cost.count(cost[0]) == len(cost): + template.same_cost_variants = True + + @api.multi + def _compute_product_template_field(self): + for template in self: + if len(template.product_variant_ids) > 1: + variant_prices = template.mapped( + 'product_variant_ids.standard_price') + template.standard_price = min(variant_prices) + else: + template.standard_price = \ + template.product_variant_ids.standard_price + + same_cost_variants = fields.Boolean(compute=_compute_same_cost_variants) + standard_price = fields.Float(compute=_compute_product_template_field) + + @api.multi + def update_variants_standard_price(self): + action = { + 'name': _('Standard price update variants'), + 'type': 'ir.actions.act_window', + 'res_model': 'variant.standard.price.update.wiz', + 'view_type': 'form', + 'view_mode': 'form', + 'target': 'new', + } + return action + + @api.multi + def write(self, vals): + if 'standard_price' in vals: + variants = self.mapped('product_variant_ids') + variants.write({ + 'standard_price': vals['standard_price'], + }) + return super(ProductTemplate, self).write(vals) diff --git a/product_variant_standard_price_update/static/description/icon.png b/product_variant_standard_price_update/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/product_variant_standard_price_update/static/description/icon.png differ diff --git a/product_variant_standard_price_update/tests/__init__.py b/product_variant_standard_price_update/tests/__init__.py new file mode 100644 index 000000000..4877d4fe0 --- /dev/null +++ b/product_variant_standard_price_update/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_product_variant_standard_price_update diff --git a/product_variant_standard_price_update/tests/test_product_variant_standard_price_update.py b/product_variant_standard_price_update/tests/test_product_variant_standard_price_update.py new file mode 100644 index 000000000..48ed5a70e --- /dev/null +++ b/product_variant_standard_price_update/tests/test_product_variant_standard_price_update.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests import common + + +class TestProductVariantStandardPriceUpdate(common.SavepointCase): + + @classmethod + def setUpClass(self): + super(TestProductVariantStandardPriceUpdate, self).setUpClass() + self.ProductTemplate = self.env['product.template'] + self.product_template = self.ProductTemplate.create({ + 'name': 'Product - template - Test', + 'standard_price': 100.00, + }) + self.attribute = self.env['product.attribute'].create({ + 'name': 'Test Attribute', + }) + self.value1 = self.env['product.attribute.value'].create({ + 'name': 'Value 1', + 'attribute_id': self.attribute.id, + }) + self.value2 = self.env['product.attribute.value'].create({ + 'name': 'Value 2', + 'attribute_id': self.attribute.id, + }) + self.product_template_var = self.ProductTemplate.create({ + 'name': 'Product - template - Test', + 'standard_price': 100.00, + 'attribute_line_ids': [ + (0, 0, { + 'attribute_id': self.attribute.id, + 'value_ids': [(6, 0, [self.value1.id, self.value2.id])] + })], + }) + + def test_update_template_standard_price(self): + self.product_template.standard_price = 150.00 + self.assertTrue(self.product_template.same_cost_variants) + self.assertEquals(self.product_template.standard_price, 150.00) + + def test_update_variant_standard_price(self): + variant = self.product_template_var.product_variant_ids[0] + variant.standard_price = 150.00 + self.assertFalse(self.product_template_var.same_cost_variants) + self.assertEquals(self.product_template_var.standard_price, 100.00) + + def test_update_simple_product_standard_price(self): + self.product_template.standard_price = 300.00 + self.assertTrue(self.product_template.same_cost_variants) + self.assertEquals(self.product_template.standard_price, 300.00) + + def test_update_wizard_action(self): + res = self.product_template_var.update_variants_standard_price() + self.assertEquals(res['name'], 'Standard price update variants') + self.assertEquals(res['type'], 'ir.actions.act_window') + + def test_update_product_standard_price_wiz(self): + wiz_obj = self.env['variant.standard.price.update.wiz'].with_context( + active_model='product.template', + active_ids=self.product_template_var.ids + ) + wiz = wiz_obj.create({'standard_price': 350.00}) + wiz.action_apply() + self.assertTrue(self.product_template_var.same_cost_variants) + self.assertEquals(self.product_template_var.standard_price, 350.00) diff --git a/product_variant_standard_price_update/views/product_view.xml b/product_variant_standard_price_update/views/product_view.xml new file mode 100644 index 000000000..f8b56c233 --- /dev/null +++ b/product_variant_standard_price_update/views/product_view.xml @@ -0,0 +1,42 @@ + + + + + + product.template + + + + + + + {'invisible': [ + ('same_cost_variants', '=', False), + ('product_variant_count', '>', 0) + ]} + + + {'invisible': [ + ('same_cost_variants', '=', False), + ('product_variant_count', '>', 0) + ]} + + +
+ Different cost price by variants. +
+
+
+
+ +
diff --git a/product_variant_standard_price_update/wizards/__init__.py b/product_variant_standard_price_update/wizards/__init__.py new file mode 100644 index 000000000..6e3558157 --- /dev/null +++ b/product_variant_standard_price_update/wizards/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import product_variant_standard_price_update diff --git a/product_variant_standard_price_update/wizards/product_variant_standard_price_update.py b/product_variant_standard_price_update/wizards/product_variant_standard_price_update.py new file mode 100644 index 000000000..c734dcd3c --- /dev/null +++ b/product_variant_standard_price_update/wizards/product_variant_standard_price_update.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2016 Sergio Teruel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models +from openerp.addons.decimal_precision import decimal_precision as dp + + +class UpdateVariantStandardPrice(models.TransientModel): + _name = 'variant.standard.price.update.wiz' + + standard_price = fields.Float( + string='Cost Price', + digits=dp.get_precision('Product Price'), + required=True, + default=0.0, + ) + + def _update_standard_price(self, product_template, new_price): + self.ensure_one() + product_template.product_variant_ids.write({ + 'standard_price': new_price, + }) + + @api.multi + def action_apply(self): + model = self.env.context['active_model'] + active_ids = self.env.context['active_ids'] + product_template = self.env[model].browse(active_ids) + self._update_standard_price(product_template, self.standard_price) + return {'type': 'ir.actions.act_window_close'} diff --git a/product_variant_standard_price_update/wizards/product_variant_standard_price_update.xml b/product_variant_standard_price_update/wizards/product_variant_standard_price_update.xml new file mode 100644 index 000000000..bda826f9b --- /dev/null +++ b/product_variant_standard_price_update/wizards/product_variant_standard_price_update.xml @@ -0,0 +1,27 @@ + + + + + + + Product Wizard Change Standard Price + variant.standard.price.update.wiz + +
+
+ You can change cost price for all product variants.
+
+ + + + +
+
+
+ +