Commit 6febdb21 authored by Jérome Perrin's avatar Jérome Perrin

trade: test Stock Report with unit conversions

parent abe20f8c
...@@ -142,14 +142,33 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -142,14 +142,33 @@ class TestTradeReports(ERP5ReportTestCase):
id='Organisation_3',) id='Organisation_3',)
# create unit categories # create unit categories
for unit_id in ('kg', 'g',): if not self.portal_categories.quantity_unit.has_key('mass'):
if not self.portal_categories['quantity_unit'].has_key(unit_id):
self.portal_categories.quantity_unit.newContent( self.portal_categories.quantity_unit.newContent(
portal_type='Category',
id='mass')
for unit_id in ('kg', 'g',):
if not self.portal_categories.quantity_unit.mass.has_key(unit_id):
self.portal_categories.quantity_unit.mass.newContent(
portal_type='Category', portal_type='Category',
title=unit_id.title(), title=unit_id.title(),
reference=unit_id, reference=unit_id,
id=unit_id) id=unit_id)
# and corresponding unit conversion group
if not self.portal.quantity_unit_conversion_module.has_key('mass_conversion_group'):
self.portal.quantity_unit_conversion_module.newContent(
portal_type='Quantity Unit Conversion Group',
id='mass_conversion_group',
quantity_unit_value=self.portal_categories.quantity_unit.mass.g,
).validate()
self.portal.quantity_unit_conversion_module.mass_conversion_group.newContent(
portal_type='Quantity Unit Conversion Definition',
id='ton',
quantity_unit_value=self.portal_categories.quantity_unit.mass.kg,
quantity=1000,
).validate()
self.tic()
# Create resources # Create resources
module = self.portal.product_module module = self.portal.product_module
if not module.has_key('product_B'): if not module.has_key('product_B'):
...@@ -158,7 +177,7 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -158,7 +177,7 @@ class TestTradeReports(ERP5ReportTestCase):
id='product_B', id='product_B',
title='product_B', title='product_B',
reference='ref 1', reference='ref 1',
quantity_unit='kg' quantity_unit='mass/kg'
) )
if not module.has_key('product_A'): if not module.has_key('product_A'):
module.newContent( module.newContent(
...@@ -166,7 +185,7 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -166,7 +185,7 @@ class TestTradeReports(ERP5ReportTestCase):
id='product_A', id='product_A',
title='product_A', title='product_A',
reference='ref 2', reference='ref 2',
quantity_unit='g', quantity_unit_list=('mass/g', 'mass/kg'),
default_purchase_supply_line_base_price=3, default_purchase_supply_line_base_price=3,
default_internal_supply_line_base_price=5, default_internal_supply_line_base_price=5,
default_sale_supply_line_base_price=7, default_sale_supply_line_base_price=7,
...@@ -950,7 +969,7 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -950,7 +969,7 @@ class TestTradeReports(ERP5ReportTestCase):
self.tic() self.tic()
def _createConfirmedSalePackingListForStockReportTest(self): def _createConfirmedSalePackingListForStockReportTest(self, quantity=1, quantity_unit_value=None):
confirmed_sale_packing_list = self.portal.sale_packing_list_module.newContent( confirmed_sale_packing_list = self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List', portal_type='Sale Packing List',
title='%s 1' % self.id(), title='%s 1' % self.id(),
...@@ -966,8 +985,9 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -966,8 +985,9 @@ class TestTradeReports(ERP5ReportTestCase):
confirmed_sale_packing_list.newContent( confirmed_sale_packing_list.newContent(
portal_type='Sale Packing List Line', portal_type='Sale Packing List Line',
resource_value=self.portal.product_module.product_A, resource_value=self.portal.product_module.product_A,
quantity=1, quantity=quantity,
price=10, price=10,
quantity_unit_value=quantity_unit_value,
) )
confirmed_sale_packing_list.confirm() confirmed_sale_packing_list.confirm()
...@@ -1105,6 +1125,31 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -1105,6 +1125,31 @@ class TestTradeReports(ERP5ReportTestCase):
inventory=66, inventory=66,
quantity_unit='') quantity_unit='')
def testStockReport_unit_conversion(self):
self._createConfirmedSalePackingListForStockReportTest(
quantity=0.5,
quantity_unit_value=self.portal.portal_categories.quantity_unit.mass.kg,
)
request = self.portal.REQUEST
request.form['at_date'] = DateTime(2007, 3, 3)
request.form['node_category'] = 'site/demo_site_A'
request.form['simulation_period'] = 'future'
line_list = self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
get_value('default',
render_format='list', REQUEST=self.portal.REQUEST)
data_line_list = [l for l in line_list if l.isDataLine()]
self.assertEqual(1, len(data_line_list))
self.checkLineProperties(
data_line_list[0],
resource_title='product_A',
resource_reference='ref 2',
variation_category_item_list=[],
inventory=500,
quantity_unit='G')
def _createInventoryForStockReportWithPositiveOrNegativeOrZeroStockTest(self): def _createInventoryForStockReportWithPositiveOrNegativeOrZeroStockTest(self):
# Create inventories # Create inventories
self._makeOneInventory( self._makeOneInventory(
......
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