Commit 4f0bdaab authored by Jérome Perrin's avatar Jérome Perrin

pdm/trade: Support supply line for a product_line

A supply line defined for a product line will apply to all resources
member of this product line.
parent 38570101
......@@ -66,6 +66,9 @@ if context.getSource():\n
if context.getDestination():\n
base_category_tuple += (\'destination\',)\n
\n
if context.hasProductLine():\n
base_category_tuple += (\'product_line\', )\n
\n
if context.getParentValue().getParentValue().getPortalType() in (\n
## XXX There is no portal type group for trade conditions.\n
\'Sale Trade Condition\',\n
......
......@@ -68,6 +68,9 @@ if context.getSource():\n
if context.getDestination():\n
base_category_tuple += (\'destination\',)\n
\n
if context.hasProductLine():\n
base_category_tuple += (\'product_line\', )\n
\n
if context.getParentValue().getPortalType() in (\n
## XXX There is no portal type group for trade conditions.\n
\'Sale Trade Condition\',\n
......
......@@ -178,6 +178,10 @@ if specialise_set:\n
kw[\'categories\'] = kw.get(\'categories\', []) + [\'specialise/%s\' % x for x in specialise_set]\n
\n
if resource is not None:\n
product_line = resource.getProductLine()\n
if product_line:\n
kw[\'categories\'] = kw.get(\'categories\', []) + [\'product_line/%s\' % product_line]\n
\n
if isPricingOptimise():\n
return getOptimisedPriceCalculationOperandDict(default=default, context=context, **kw)\n
else:\n
......
......@@ -186,6 +186,16 @@ class TestResource(ERP5TypeTestCase):
quantity=0.001)
gram_definition.validate()
# create some product line categories
product_line = self.portal.portal_categories.product_line
if product_line._getOb('a', None) is None:
product_line.newContent(
id='a',
portal_type='Category')
if product_line._getOb('b', None) is None:
product_line.newContent(
id='b',
portal_type='Category')
def stepCreateResource(self, sequence=None, sequence_list=None, **kw):
"""
......@@ -1067,6 +1077,43 @@ class TestResource(ERP5TypeTestCase):
self.assertEqual(1000, sale_order_line.getPrice())
self.assertEqual(5000, sale_order_line.getTotalPrice())
def testGetPriceProductLine(self):
"""Test supply line set for a product line.
"""
# This supply line defines a price applicable for all resources member
# of product line a
supply = self.portal.getDefaultModule(self.sale_supply_portal_type).newContent(
portal_type=self.sale_supply_portal_type)
supply_line = supply.newContent(portal_type=self.sale_supply_line_portal_type)
supply_line.setProductLineValue(self.portal.portal_categories.product_line.a)
supply_line.setBasePrice(1000)
supply.validate()
resource_a = self.portal.getDefaultModule(self.product_portal_type)\
.newContent(portal_type=self.product_portal_type)
resource_a.setProductLineValue(self.portal.portal_categories.product_line.a)
resource_b = self.portal.getDefaultModule(self.product_portal_type)\
.newContent(portal_type=self.product_portal_type)
resource_b.setProductLineValue(self.portal.portal_categories.product_line.b)
self.tic()
sale_order_line = self.portal.getDefaultModule("Sale Order").newContent(
portal_type='Sale Order').newContent(
portal_type=self.sale_order_line_portal_type,
resource_value=resource_a,
quantity=1)
# resource_a is member of product_line/a, so our supply line applies.
self.assertEqual(1000, sale_order_line.getPrice())
sale_order_line = self.portal.getDefaultModule("Sale Order").newContent(
portal_type='Sale Order').newContent(
portal_type=self.sale_order_line_portal_type,
resource_value=resource_b,
quantity=1)
# resource_b is member of product_line/b, so our supply line does not apply.
self.assertEqual(None, sale_order_line.getPrice())
def testQuantityPrecision(self):
"""test how to define quantity precision on resources.
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment