From 9abbb104d0f97600bd98c895664fb6675ce25848 Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Wed, 21 Apr 2010 19:57:13 +0530 Subject: [PATCH] [IMP]: lunch: Develop Yaml test case and change category_id field type selection to many2one bzr revid: atp@tinyerp.co.in-20100421142713-uyt4qp321a6gmotr --- addons/lunch/__openerp__.py | 5 +- addons/lunch/lunch.py | 14 +--- addons/lunch/lunch_view.xml | 2 +- addons/lunch/test/test_lunch.yml | 122 +++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 addons/lunch/test/test_lunch.yml diff --git a/addons/lunch/__openerp__.py b/addons/lunch/__openerp__.py index 782d5f49df9..efde2f16e61 100644 --- a/addons/lunch/__openerp__.py +++ b/addons/lunch/__openerp__.py @@ -47,7 +47,10 @@ 'lunch_report.xml', #'process/lunch_process.xml' ], - "demo_xml": ['lunch_demo.xml'], + "demo_xml": ['lunch_demo.xml', + ], + "test": ['test/test_lunch.yml' + ], "installable": True, } diff --git a/addons/lunch/lunch.py b/addons/lunch/lunch.py index 207d7ebe940..a986dc25953 100644 --- a/addons/lunch/lunch.py +++ b/addons/lunch/lunch.py @@ -42,21 +42,9 @@ class lunch_product(osv.osv): _name = 'lunch.product' _description = "Lunch Product" - def _category_name_get(self, cr, uid, context={}): - - """ Get category name - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param context: A standard dictionary for contextual values""" - - obj = self.pool.get('lunch.category') - cat_ids = obj.search(cr, uid, []) - res = obj.read(cr, uid, cat_ids, ['name', 'category']) - return [(str(r['id']), r['name']) for r in res]+ [('0','')] - _columns = { 'name': fields.char('Name', size=50, required=True), - 'category_id': fields.selection(_category_name_get, 'Category', size=32), + 'category_id': fields.many2one('lunch.category', 'Category'), 'description': fields.char('Description', size=128, required=False), 'price': fields.float('Price', digits=(16,2)), 'active': fields.boolean('Active'), diff --git a/addons/lunch/lunch_view.xml b/addons/lunch/lunch_view.xml index 962330c1ea2..ab3d6792683 100644 --- a/addons/lunch/lunch_view.xml +++ b/addons/lunch/lunch_view.xml @@ -195,7 +195,7 @@
- + diff --git a/addons/lunch/test/test_lunch.yml b/addons/lunch/test/test_lunch.yml new file mode 100644 index 00000000000..01ed21b690a --- /dev/null +++ b/addons/lunch/test/test_lunch.yml @@ -0,0 +1,122 @@ +- | + In order to test the Lunch module in OpenERP, + I will create one lunch order and then check the effect on cashboxes and cashmoves + +- | + Given that I have a category of lunch products "Sandwich". +- + !record {model: lunch.category, id: lunch_category_burger0}: + name: Burger +- | + Given that I have a product "Club1" in this category with a price of "2.75". + +- + !record {model: lunch.product, id: lunch_product_club1}: + category_id: lunch_category_burger0 + name: Club1 + price: 2.75 +- | + Given that I have a cashbox "Cashbox" +- + !record {model: lunch.cashbox, id: lunch_cashbox_cashbox0}: + manager: base.user_root + name: CashBox +- | + I create a lunch order "LU001" for the "Club1" product +- | + When I select the product "club1", the price of 2.75 is automatically proposed +- + !record {model: lunch.order, id: lunch_order_0}: + date: '2010-04-19' + product: 'lunch_product_club1' + price: 2.75 + user_id: base.user_root + +- | + I check that lunch order is on draft state after having created it. +- + !assert {model: lunch.order, id: lunch_order_0}: + - state == 'draft' +- | + I confirm the order "LU001" using the "Confirm Order" wizard. +- + !record {model: lunch.order.confirm, id: lunch_order_confirm_0}: + confirm_cashbox: 'lunch_cashbox_cashbox0' +- + !python {model: lunch.order.confirm}: | + self.confirm(cr, uid, [ref('lunch_order_confirm_0')], {'active_ids': [ref('lunch_order_0')]}) +- | + I check that the Cash Moves have been generated with the right box + name +- + # !assert {model: lunch.order, id: lunch_order_0}: + # - cashmove != False + +- | + I check that the Total on the cashbox is -2.75 + +- + !assert {model: lunch.cashbox, id: lunch_cashbox_cashbox0}: + - sum_remain == -2.75 + +- | + I create a new lunch order "LU002" for the "Club" product, at another date. +- + !record {model: lunch.order, id: lunch_order_1}: + date: '2010-04-22' + product: 'lunch_product_club1' + price: 2.75 + user_id: base.user_root + +- | + I confirm this order.open wizard and select cashbox. +- + !record {model: lunch.order.confirm, id: lunch_order_confirm_1}: + confirm_cashbox: 'lunch_cashbox_cashbox0' +- + Now I click on "Confirm Order" button of this wizard. +- + !python {model: lunch.order.confirm}: | + self.confirm(cr, uid, [ref('lunch_order_confirm_1')], {'active_ids': [ref('lunch_order_1')]}) + +- | + I check that the Total on the cashbox is -5.50 +- + !assert {model: lunch.cashbox, id: lunch_cashbox_cashbox0}: + - sum_remain == -5.50 +- | + I reset the cashbox to zero using the "Set CashBox to Zero" wizard. +- + !record {model: lunch.cashbox.clean, id: lunch_cashbox_clean_0}: + {} +- + !python {model: lunch.cashbox.clean, id: lunch_cashbox_clean_0}: | + self.set_to_zero(cr, uid, [ref('lunch_cashbox_clean_0')], {'active_ids': [ref('lunch_cashbox_cashbox0')]}) + +- | + I check that the Total on the cashbox is 0.0 +- + !assert {model: lunch.cashbox, id: lunch_cashbox_cashbox0}: + - sum_remain == 0.00 + +- | + I cancel the order "LU002" +- + !record {model: lunch.order.cancel, id: lunch_order_cancel_0}: + {} +- + !python {model: lunch.order.cancel}: | + self.cancel(cr, uid, [ref('lunch_order_cancel_0')], {'active_ids': [ref('lunch_order_1')]}) + +- | + I test that the Cash Moves revord have been removed for the order LU002. +- + !assert {model: lunch.order, id: lunch_order_1}: + - cashmove == False + +- | + I check that the Total on the cashbox is -2.75 +- + !assert {model: lunch.cashbox, id: lunch_cashbox_cashbox0}: + - sum_remain == -2.75 + \ No newline at end of file