Skip to content

Commit

Permalink
[10.0][IMP] website_sale_qty: Add option to hide implicit price tier
Browse files Browse the repository at this point in the history
  • Loading branch information
kellylougheed committed Mar 17, 2017
1 parent 1db27ba commit 890a62f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
6 changes: 5 additions & 1 deletion website_sale_qty/README.rst
Expand Up @@ -19,7 +19,11 @@ To install this module, simply follow the standard install process.
Configuration
=============

No configuration is needed or possible.
* A tier with a minimum quantity of one is automatically created. If you would
like to turn off this implicit tier of one, you may select "Website Sale -
Quantity Tiers (No Implicit)" from the Customize menu on the product page
under "Website Sale - Quantity Tiers." Note that "Website Sale - Quantity Tiers"
under "Product" must be enabled as well.

Usage
=====
Expand Down
9 changes: 1 addition & 8 deletions website_sale_qty/demo/product_pricelist_item_demo.xml
Expand Up @@ -6,14 +6,6 @@
-->

<odoo>
<record id="template_level_price_qty_1" model="product.pricelist.item">
<field name="pricelist_id" ref="product.list0"/>
<field name="applied_on">1_product</field>
<field name="compute_price">fixed</field>
<field name="fixed_price">320</field>
<field name="product_tmpl_id" ref="product.product_product_6_product_template"/>
<field name="min_quantity">1</field>
</record>

<record id="template_level_price_qty_5" model="product.pricelist.item">
<field name="pricelist_id" ref="product.list0"/>
Expand All @@ -32,4 +24,5 @@
<field name="product_tmpl_id" ref="product.product_product_6_product_template"/>
<field name="min_quantity">10</field>
</record>

</odoo>
18 changes: 15 additions & 3 deletions website_sale_qty/models/product_template.py
Expand Up @@ -13,8 +13,12 @@ class ProductTemplate(models.Model):
help='Unit prices by pricelist and minimum quantity',
)

tiers_no_implicit = fields.Serialized(
compute='_compute_tiers_no_implicit',
)

@api.multi
def _compute_price_quantity_tiers(self):
def _compute_price_quantity_tiers(self, implicit_pricing=True):
pricelists = self.env['product.pricelist'].search([('id', '>', 0)])

for record in self:
Expand All @@ -40,7 +44,8 @@ def _compute_price_quantity_tiers(self):
min_quantities.add(
1 if price.min_quantity < 1 else price.min_quantity
)
min_quantities.add(1)
if implicit_pricing:
min_quantities.add(1)

list_results = set([])
for min_qty in min_quantities:
Expand All @@ -57,4 +62,11 @@ def _compute_price_quantity_tiers(self):
list_results = []
results[pricelist.id] = list_results

record.price_quantity_tiers = results
if implicit_pricing:
record.price_quantity_tiers = results
else:
record.tiers_no_implicit = results

@api.multi
def _compute_tiers_no_implicit(self):
self._compute_price_quantity_tiers(False)
29 changes: 29 additions & 0 deletions website_sale_qty/tests/test_product_template.py
Expand Up @@ -27,6 +27,10 @@ def setUp(self):
'currency_id': self.env.ref('base.USD').id,
'name': 'Test Pricelist 2',
})
self.test_pricelist_3 = self.env['product.pricelist'].create({
'currency_id': self.env.ref('base.USD').id,
'name': 'Test Pricelist 3',
})
self.pricelists = self.env['product.pricelist'].search([
('id', '>', 0),
])
Expand Down Expand Up @@ -213,3 +217,28 @@ def test_price_quantity_tiers_first_variant_price_rule(self):
self.test_template.price_quantity_tiers[self.test_pricelist_1.id],
[],
)

def test_tiers_no_implicit(self):
'''The tiers_no_implicit field should be a price tier
without a min quantity of one'''
self.env['product.pricelist.item'].create({
'pricelist_id': self.test_pricelist_3.id,
'applied_on': '1_product',
'compute_price': 'fixed',
'fixed_price': 1,
'product_tmpl_id': self.test_template.id,
'min_quantity': 2,
})
self.env['product.pricelist.item'].create({
'pricelist_id': self.test_pricelist_3.id,
'applied_on': '1_product',
'compute_price': 'fixed',
'fixed_price': 0.8,
'product_tmpl_id': self.test_template.id,
'min_quantity': 20,
})

self.assertEqual(
self.test_template.tiers_no_implicit[self.test_pricelist_3.id],
[(2, 1), (20, 0.8)],
)
24 changes: 24 additions & 0 deletions website_sale_qty/views/website_sale_qty_view.xml
Expand Up @@ -37,6 +37,30 @@
</xpath>
</template>

<template id="product_no_implicit" inherit_id="website_sale_qty.product" customize_show="True" name="Website Sale - Quantity Tiers (No Implicit)">
<xpath expr="//ul" position="replace">
<t t-set="pricelist" t-value="website.get_current_pricelist()"/>
<t t-set="price_qty_tiers" t-value="product.tiers_no_implicit[pricelist.id]"/>
<t t-if="len(price_qty_tiers) &gt; 0">
<ul class="list-unstyled" style="margin-bottom: 5px;">
<t t-foreach="price_qty_tiers" t-as="price_qty_tier">
<li class="form-group" style="margin: 0;">
<label class="control-label">
<input class="js-pqt-input" type="radio" name="price_qty_tiers" t-att-value="price_qty_tier[0]" style="vertical-align: top; margin-right: 5px;"/>
<span t-esc="price_qty_tier[0]"/>
<span class="badge"><t t-esc="price_qty_tier[0] * price_qty_tier[1]" t-esc-options="{
&quot;widget&quot;: &quot;monetary&quot;,
&quot;from_currency&quot;: &quot;pricelist.currency_id&quot;,
&quot;display_currency&quot;: &quot;website.currency_id&quot;
}"/></span>
</label>
</li>
</t>
</ul>
</t>
</xpath>
</template>

<template id="product_lowest_tier" inherit_id="product" customize_show="True" name="Lowest Tier Quantity">
<xpath expr="//input[@type='radio'][position()=1]" position="attributes">
<attribute name="checked">checked</attribute>
Expand Down

0 comments on commit 890a62f

Please sign in to comment.