Add category as matching criteria
issue6297 review28041002
This commit is contained in:
1 parent
cb1c3c814c
commit
457f52e951
6 files changed
+72
-7
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Add category as matching criteria
|
||||
|
||||
Version 4.2.0 - 2016-11-28
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
|
||||
|
||||
+13
-3
@@ -53,7 +53,9 @@ class PriceList(ModelSQL, ModelView):
|
||||
pattern = {}
|
||||
|
||||
pattern = pattern.copy()
|
||||
pattern['product'] = product and product.id or None
|
||||
if product:
|
||||
pattern['categories'] = [c.id for c in product.categories]
|
||||
pattern['product'] = product.id
|
||||
pattern['quantity'] = Uom.compute_qty(uom, quantity,
|
||||
product.default_uom, round=False) if product else quantity
|
||||
|
||||
@@ -71,9 +73,12 @@ class PriceListLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
|
||||
|
||||
price_list = fields.Many2One('product.price_list', 'Price List',
|
||||
required=True, ondelete='CASCADE')
|
||||
category = fields.Many2One(
|
||||
'product.category', "Category", ondelete='CASCADE')
|
||||
product = fields.Many2One('product.product', 'Product', ondelete='CASCADE')
|
||||
quantity = fields.Float('Quantity', digits=(16, Eval('unit_digits', 2)),
|
||||
depends=['unit_digits'])
|
||||
depends=['unit_digits'],
|
||||
help="Minimal quantity in the product default UoM.")
|
||||
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||
'on_change_with_unit_digits')
|
||||
formula = fields.Char('Formula', required=True,
|
||||
@@ -107,7 +112,6 @@ class PriceListLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
|
||||
def on_change_with_unit_digits(self, name=None):
|
||||
if self.product:
|
||||
return self.product.default_uom.digits
|
||||
return 2
|
||||
|
||||
@classmethod
|
||||
def validate(cls, lines):
|
||||
@@ -138,6 +142,12 @@ class PriceListLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
|
||||
quantity = pattern.pop('quantity')
|
||||
if self.quantity is not None and self.quantity > quantity:
|
||||
return False
|
||||
if 'categories' in pattern:
|
||||
pattern = pattern.copy()
|
||||
categories = pattern.pop('categories')
|
||||
if (self.category is not None
|
||||
and self.category.id not in categories):
|
||||
return False
|
||||
return super(PriceListLine, self).match(pattern)
|
||||
|
||||
def get_unit_price(self, **context):
|
||||
|
||||
@@ -78,6 +78,56 @@ class ProductPriceListTestCase(ModuleTestCase):
|
||||
quantity, unit),
|
||||
result)
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_category(self):
|
||||
"Test price list with category"
|
||||
pool = Pool()
|
||||
Category = pool.get('product.category')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Uom = pool.get('product.uom')
|
||||
PriceList = pool.get('product.price_list')
|
||||
|
||||
category = Category(name="Category")
|
||||
category.save()
|
||||
|
||||
unit, = Uom.search([('name', '=', 'Unit')])
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
template = Template(
|
||||
name="Template",
|
||||
list_price=Decimal(10),
|
||||
cost_price=Decimal(3),
|
||||
default_uom=unit,
|
||||
products=None,
|
||||
categories=[category],
|
||||
)
|
||||
template.save()
|
||||
product = Product(template=template)
|
||||
product.save()
|
||||
|
||||
price_list, = PriceList.create([{
|
||||
'name': "Price List",
|
||||
'lines': [('create', [{
|
||||
'category': category.id,
|
||||
'formula': 'unit_price * 0.8',
|
||||
}, {
|
||||
'formula': 'unit_price',
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(
|
||||
price_list.compute(None, product, product.list_price, 1, unit),
|
||||
Decimal(8))
|
||||
|
||||
template.categories = []
|
||||
template.save()
|
||||
|
||||
self.assertEqual(
|
||||
price_list.compute(None, product, product.list_price, 1, unit),
|
||||
Decimal(10))
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
|
||||
@@ -4,14 +4,15 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="price_list"/>
|
||||
<field name="price_list"/>
|
||||
<newline/>
|
||||
<label name="sequence"/>
|
||||
<field name="sequence"/>
|
||||
<label name="category"/>
|
||||
<field name="category"/>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="sequence"/>
|
||||
<field name="sequence"/>
|
||||
<newline/>
|
||||
<separator id="formula" colspan="4"/>
|
||||
<label name="formula"/>
|
||||
<field name="formula" colspan="3"/>
|
||||
</form>
|
||||
@@ -4,6 +4,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="price_list"/>
|
||||
<field name="sequence"/>
|
||||
<field name="category"/>
|
||||
<field name="product"/>
|
||||
<field name="quantity"/>
|
||||
<field name="formula"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree sequence="sequence">
|
||||
<field name="category"/>
|
||||
<field name="product"/>
|
||||
<field name="quantity"/>
|
||||
<field name="formula"/>
|
||||
|
||||
Reference in new issue
Block a user