-
-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] pricelist_per_product: Improvements based on PR
* 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
Showing
8 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters