Skip to content

Commit

Permalink
[IMP] pricelist_per_product: Improvements based on PR
Browse files Browse the repository at this point in the history
* Add show products button to Pricelist view
* Make product.template Pricelist view inline-editable
* Add `product.pricelist.item` tree to product.pricelist view
* Add tests
  • Loading branch information
Ted Salmon committed Feb 28, 2017
1 parent b7bfe7d commit 7837c39
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 3 deletions.
1 change: 1 addition & 0 deletions pricelist_per_product/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Contributors
* David BEAL <david.beal@akretion.com>
* Sylvain CALADOR <sylvain.calador@akretion.com>
* Brett Wood <bwood@laslabs.com>
* Ted Salmon <tsalmon@laslabs.com>

Maintainer
----------
Expand Down
1 change: 1 addition & 0 deletions pricelist_per_product/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
4 changes: 4 additions & 0 deletions pricelist_per_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import product_pricelist
40 changes: 40 additions & 0 deletions pricelist_per_product/models/product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, fields, models


class ProductPricelist(models.Model):
_inherit = 'product.pricelist'

product_template_count = fields.Integer(
compute='_compute_product_template_count',
string='Template with this Pricelist',
help='Number of Product Template with this Pricelist',
)
product_item_ids = fields.One2many(
comodel_name='product.pricelist.item',
inverse_name='pricelist_id',
)

@api.multi
def _compute_product_template_count(self):
""" Count the number of ``product,template`` in the pricelist """
total = [pt_id for pt_id in self.item_ids.mapped('product_tmpl_id')]
self.product_template_count = len(total)

@api.multi
def button_template_in_pricelist(self):
""" Return a tree form of ``product.template`` for the pricelist """
self.ensure_one()
pids = []
for rec in self.item_ids.mapped('product_tmpl_id'):
pids.append(rec.id)
return {
'type': 'ir.actions.act_window',
'target': 'current',
'domain': [('id', 'in', pids)],
'view_mode': 'tree,form',
'res_model': 'product.template',
}
4 changes: 4 additions & 0 deletions pricelist_per_product/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_product_pricelist
42 changes: 42 additions & 0 deletions pricelist_per_product/tests/test_product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class TestProductPricelist(TransactionCase):

def setUp(self):
super(TestProductPricelist, self).setUp()
self.pricelist = self.env['product.pricelist'].create({
'name': 'Test Pricelist',
'currency_id': self.env.ref('base.USD').id,
})
self.pricelist_item = self.env['product.pricelist.item'].create({
'applied_on': '1_product',
'base': 'list_price',
'name': 'Test Pricelist Item',
'pricelist_id': self.pricelist.id,
'product_tmpl_id': self.env.ref('product.product_product_4').id,
'sequence': 5,
})

def test_compute_product_template_count(self):
""" It should test that the right template count is returned """
self.pricelist._compute_product_template_count()
self.assertTrue(self.pricelist.product_template_count == 1)

def test_button_template_in_pricelist(self):
""" It should return a view with a domain for the products in the
pricelist """
pids = self.env.ref('product.product_product_4').ids
exp = {
'type': 'ir.actions.act_window',
'target': 'current',
'domain': [('id', 'in', pids)],
'view_mode': 'tree,form',
'res_model': 'product.template',
}
res = self.pricelist.button_template_in_pricelist()
self.assertEqual(exp, res)
34 changes: 34 additions & 0 deletions pricelist_per_product/views/product_pricelist_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,43 @@
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="button_template_in_pricelist"
class="oe_inline oe_stat_button" type="object"
icon="fa-cube"
help="Click to view product templates in this Pricelist">
<field name="product_template_count" widget="statinfo" string="Show Products" />
</button>
</xpath>
<xpath expr="//field[@name='item_ids']" position="attributes">
<attribute name="context">{'default_base':'list_price', 'default_pricelist_id': id}</attribute>
</xpath>
<xpath expr="//sheet" position="inside">
<notebook>
<page name="grid" string="Product Grid">
<group col="4">
<field name="product_item_ids" nolabel="1">
<tree string="Price Grid" editable="1">
<field name="id" invisible="1"/>
<field name="product_id"/>
<field name="sequence" widget="handle"/>
<field name="price_surcharge" string="Price"/>
<field name="product_tmpl_id"/>
<button name="button_product"
icon="terp-stock_symbol-selection"
class="oe_link" type="object"
attrs="{'invisible': [
('product_tmpl_id', '=', False),
('product_id', '=', False)]}"
help="Click to see this product"/>
<field name="price_discount" string="Disc." invisible="1"/>
<field name="base" string="Base" invisible="1"/>
</tree>
</field>
</group>
</page>
</notebook>
</xpath>
</field>
</record>

Expand Down
13 changes: 10 additions & 3 deletions pricelist_per_product/views/product_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
<field name="name">product.template.common.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="groups_id" eval="[(6, 0, [ref('product.group_pricelist_item')])]" />
<field name="arch" type="xml">
<xpath expr="//field[@name='item_ids']" position="attributes">
<attribute name="context">{'default_base':'list_price', 'default_applied_on':'1_product', 'default_product_tmpl_id': id}</attribute>
</xpath>
<xpath expr="//tree[field[@name='pricelist_id']]" position="attributes">
<attribute name="editable" />
<xpath expr="//field[@name='item_ids']" position="inside">
<tree string="Pricelist Items" editable="bottom" create="1"
delete="1">
<field name="pricelist_id" string="Pricelist" required="1"/>
<field name="fixed_price" string="Price" required="1"/>
<field name="min_quantity"/>
<field name="date_start"/>
<field name="date_end"/>
<field name="applied_on" invisible="1"/>
</tree>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 7837c39

Please sign in to comment.