Skip to content

Commit

Permalink
[9.0][NEW] product_variant_standard_price_update: New module to updat…
Browse files Browse the repository at this point in the history
…e cost price for all product variants
  • Loading branch information
sergio-teruel committed Dec 15, 2016
1 parent fbabc00 commit e561a3d
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 0 deletions.
69 changes: 69 additions & 0 deletions 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
<https://github.com/OCA/product-variant/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 <https://github.com/OCA/maintainer-tools/
blob/master/template/module/static/description/icon.svg>`_.


Contributors
------------

* Sergio Teruel <sergio.teruel@tecnativa.com>

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.
4 changes: 4 additions & 0 deletions product_variant_standard_price_update/__init__.py
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import models
from . import wizards
23 changes: 23 additions & 0 deletions product_variant_standard_price_update/__openerp__.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
# 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",
],
}
119 changes: 119 additions & 0 deletions 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 <sergio.teruel@tecnativa.com>\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 "<span>Different cost price by variants. </span>"
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.<br/>"
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 ""
5 changes: 5 additions & 0 deletions product_variant_standard_price_update/models/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import product
51 changes: 51 additions & 0 deletions product_variant_standard_price_update/models/product.py
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
# 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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions product_variant_standard_price_update/tests/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_product_variant_standard_price_update
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
# 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)
42 changes: 42 additions & 0 deletions product_variant_standard_price_update/views/product_view.xml
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Sergio Teruel <sergio.teruel@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>

<record id="product_template_form_view_update_standard_price"
model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id"
ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='list_price']" position="before">
<field name="same_cost_variants" invisible="1"/>
</xpath>
<xpath expr="//field[@name='standard_price']/.." position="attributes">
<attribute name="attrs">{'invisible': [
('same_cost_variants', '=', False),
('product_variant_count', '&gt;', 0)
]}</attribute>
</xpath>
<xpath expr="//label[@for='standard_price']" position="attributes">
<attribute name="attrs">{'invisible': [
('same_cost_variants', '=', False),
('product_variant_count', '&gt;', 0)
]}</attribute>
</xpath>
<xpath expr="//field[@name='standard_price']/.." position="after">
<div groups="base.group_user"
colspan="2"
attrs="{'invisible': ['|',
('same_cost_variants', '=', True),
('product_variant_count', '=', 0)]}">
<span>Different cost price by variants. </span>
<button type="object"
name="update_variants_standard_price"
string="Update variant price"/>
</div>
</xpath>
</field>
</record>

</odoo>

0 comments on commit e561a3d

Please sign in to comment.