From 5e6a1ecb7639e2bf6b7b04846e39f4293f7b3c3f Mon Sep 17 00:00:00 2001
From: Fabien Pinckaers <fp@tinyerp.com>
Date: Sun, 25 Sep 2011 17:50:50 +0200
Subject: [PATCH] [IMP] clean test YML for point_of_sale

bzr revid: fp@tinyerp.com-20110925155050-cqkwsar8azfmis87
---
 addons/point_of_sale/__openerp__.py           |   5 +-
 addons/point_of_sale/point_of_sale.py         |   3 +-
 .../point_of_sale/test/point_of_sale_test.yml | 173 ------------------
 addons/point_of_sale/wizard/pos_payment.py    |   8 +-
 4 files changed, 11 insertions(+), 178 deletions(-)
 delete mode 100644 addons/point_of_sale/test/point_of_sale_test.yml

diff --git a/addons/point_of_sale/__openerp__.py b/addons/point_of_sale/__openerp__.py
index 75d23c2ca060..7b0a35e9632a 100644
--- a/addons/point_of_sale/__openerp__.py
+++ b/addons/point_of_sale/__openerp__.py
@@ -77,8 +77,9 @@ Main features :
         'account_statement_demo.xml',
         'test/00_register_open.yml'
     ],
-    'test': ['test/point_of_sale_test.yml',
-            'test/point_of_sale_report.yml',
+    'test': [
+        'test/01_order_to_payment.yml',
+        'test/point_of_sale_report.yml'
     ],
     'installable': True,
     'certificate' : '001156338024966477869',
diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py
index b23ba71d0658..6757fc083367 100644
--- a/addons/point_of_sale/point_of_sale.py
+++ b/addons/point_of_sale/point_of_sale.py
@@ -643,7 +643,7 @@ class pos_order_line(osv.osv):
     _columns = {
         'company_id': fields.many2one('res.company', 'Company', required=True),
         'name': fields.char('Line No', size=32, required=True),
-        'notice': fields.char('Discount Notice', size=128, required=True),
+        'notice': fields.char('Discount Notice', size=128),
         'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], required=True, change_default=True),
         'price_unit': fields.float(string='Unit Price', digits=(16, 2)),
         'qty': fields.float('Quantity', digits=(16, 2)),
@@ -658,7 +658,6 @@ class pos_order_line(osv.osv):
         'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'pos.order.line'),
         'qty': lambda *a: 1,
         'discount': lambda *a: 0.0,
-        'notice': lambda *a: 'No Discount',
         'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
 
diff --git a/addons/point_of_sale/test/point_of_sale_test.yml b/addons/point_of_sale/test/point_of_sale_test.yml
deleted file mode 100644
index f565741a8a18..000000000000
--- a/addons/point_of_sale/test/point_of_sale_test.yml
+++ /dev/null
@@ -1,173 +0,0 @@
--
-  In order to test the Point of Sale in module, I will do a full flow from the sale to the paiement and invoicing.
--
-  I create a PoS with 2 PC1 and 3 PC2.
--
-  !record {model: pos.order, id: pos_order_pos0}:
-    company_id: base.main_company
-    lines:
-      - name: OL/0001
-        product_id: product.product_product_pc1
-        price_unit: 450
-        discount: 0.0
-        qty: 2.0
-      - name: OL/0002
-        product_id: product.product_product_pc2
-        price_unit: 300
-        discount: 0.0
-        qty: 3.0
-- 
-  I check that the total of the order is equal to 450 * 2 / 300 * 3
-- 
-  !python {model: pos.order}: |
-    order = self.browse(cr, uid, ref('pos_order_pos0'))
-    assert(abs(order.amount_total - 1800.0) < 0.01), "The order has a wrong amount"
-- 
-  I want to add a global discount of 5 percent using the wizard
-- 
-  !record {model: pos.discount, id: pos_discount_0}:
-    discount: 5.0
-- 
-  I click the apply button to set the discount on all lines
-- 
-  !python {model: pos.discount}: |
-    self.apply_discount(cr, uid, [ref("pos_discount_0")], {"active_model": "pos.order",
-      "active_ids": [ref("pos_order_pos0")], "active_id": ref("pos_order_pos0"), })
-- 
-  I check that the total of the order is not equal to (450 * 2 / 300 * 3)*0.95
-- 
-  !python {model: pos.order}: |
-    order = self.browse(cr, uid, ref('pos_order_pos0'))
-    assert(abs(order.amount_total - (450*2+300*3)*0.95) < 0.01), "The order has a wrong amount"
-#- 
-#  I open the register.
-#- 
-#  !record {model: pos.open.statement, id: pos_open_statement_0}:
-#    {}
-#- 
-#  I open the statement.
-#- 
-#  !python {model: pos.open.statement}: |
-#    jou_obj = self.pool.get('account.journal')
-#    statement_obj = self.pool.get('account.bank.statement')
-#    cr.execute("SELECT DISTINCT journal_id FROM pos_journal_users "
-#                    "WHERE user_id = %s ORDER BY journal_id"% (uid, ))
-#    jou_ids = map(lambda x1: x1[0], cr.fetchall())
-#    journal_ids = jou_obj.search(cr, uid, [('auto_cash', '=', True), ('type', '=', 'cash'), ('id', 'in', jou_ids)], context=context)
-#    ids = statement_obj.search(cr, uid, [('state', '=', 'open'), ('user_id', '=', uid), ('journal_id', 'in', journal_ids)], context=context)
-#    if not ids:
-#        self.open_statement(cr, uid, [ref("pos_open_statement_0")], {"lang": "en_US", "active_model":
-#          "ir.ui.menu", "active_ids": [ref("point_of_sale.menu_open_statement")], "tz":
-#          False, "active_id": ref("point_of_sale.menu_open_statement"), })
-#-
-#  I click on the "Make Payment" wizard.  
-#- 
-#  !record {model: pos.make.payment, id: pos_make_payment_0}:
-#    amount: 1615.0
-#    journal: 7
-#    payment_date: !eval time.strftime("%Y-%m-%d")
-#    payment_name: Payment
-#    product_id: product_product_hppaviliondesktoppcs0
-#    pricelist_id: product.list0
-#    partner_id: base.res_partner_agrolait
-#- 
-#  I make the payment.
-#- 
-#  !python {model: pos.make.payment}: |
-#    self.check(cr, uid, [ref("pos_make_payment_0")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("point_of_sale.pos_order_pos0")], "tz":
-#      False, "active_id": ref("point_of_sale.pos_order_pos0"), })
-#-
-#  I check the Statement lines are created automatically when payment is done.
-#-
-#  !python {model: pos.order}: |
-#   order=self.browse(cr,uid,ref("pos_order_pos0"))
-#   assert(order.statement_ids!=[]), "Statement lines not created"    
-#-
-#  When I click on Return picking button , I get three option.
-#-
-#  1. Cancel 2.Return Goods and Exchange 3.Return without Refund
-#-
-#  When I click on  Return Goods and Exchange.  
-#-  
-#  Then it allows me to define the quantity of products, which will return to the stock. 
-#- 
-#  I click on Return Picking button.
-#- 
-#  !record {model: pos.return, id: pos_return_0}:
-#    pos_moves_ids:
-#      - product_id: product_product_hppaviliondesktoppcs0
-#        quantity: 5.0
-#- 
-#  I Return the product.
-#- 
-#  !python {model: pos.return}: |
-#    self.create_returns(cr, uid, [ref("pos_return_0")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("point_of_sale.pos_order_pos0")], "tz":
-#      False, "active_id": ref("point_of_sale.pos_order_pos0"), })
-#- 
-#  Then it allows me to define the quantity of products, which will return to the stock.
-#-
-#  I select the  HP Pavilion Desktop PCs for exchange.   
-#- 
-#  !record {model: pos.add.product, id: pos_add_product_0}:
-#    product_id: product_product_hppaviliondesktoppcs0
-#    quantity: 5.0
-#-    
-#  I click on close button.
-#- 
-#  !python {model: pos.add.product}: |
-#    return_obj = self.pool.get('pos.return')
-#    context['active_ids'] = [ref("pos_order_pos0")] 
-#    return_obj.view_init(cr, uid, [],context=context)
-#    self.close_action(cr, uid, [ref("pos_add_product_0")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("pos_order_pos0")], "tz": False, "active_id": ref("pos_order_pos0"),
-#      })
-#-    
-#  I create payment.
-#- 
-#  !record {model: pos.make.payment, id: pos_make_payment_1}:
-#    amount: 680.0
-#    journal: 7
-#    payment_date: !eval time.strftime("%Y-%m-%d")
-#    payment_name: Payment
-#    product_id: product_product_hppaviliondesktoppcs0
-#    pricelist_id: product.list0
-#    partner_id: base.res_partner_agrolait
-#- 
-#  For payment, I click on  Make Payment. 
-#- 
-#  !python {model: pos.make.payment}: |
-#    self.check(cr, uid, [ref("pos_make_payment_1")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("pos_order_pos0")], "tz":
-#      False, "active_id": ref("pos_order_pos0"), })    
-#- 
-#  To check the Return without Refund . I click button "Return without Refund ".
-#- 
-#  !record {model: pos.return, id: pos_return_0}:
-#   {}
-#-
-#  The quantity which is selected in Return lines wizard is refunded.
-#- 
-#  !python {model: pos.return}: |
-#    self.create_returns2(cr, uid, [ref("pos_return_0")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("pos_order_pos0")], "tz":
-#      False, "active_id": ref("pos_order_pos0"), })
-#- 
-#  To Close order, I use the wizard "Sale Confirm".
-#- 
-#  !record {model: pos.confirm, id: pos_confirm_0}:
-#    {}
-#- 
-#  I close this order.
-#- 
-#  !python {model: pos.confirm}: |
-#    self.action_confirm(cr, uid, [ref("pos_confirm_0")], {"lang": "en_US", "active_model":
-#      "pos.order", "active_ids": [ref("pos_order_pos0")], "tz": False, "active_id": ref("pos_order_pos0"),
-#      })
-#- 
-#  I check order state is done.
-#- 
-#  !python {model: pos.order}: |
-#    order=self.browse(cr,uid,ref("pos_order_pos0"))    
-#    assert(order.state=='done'), "Order is not done"    
diff --git a/addons/point_of_sale/wizard/pos_payment.py b/addons/point_of_sale/wizard/pos_payment.py
index 251c847586e9..6b2d01d56722 100644
--- a/addons/point_of_sale/wizard/pos_payment.py
+++ b/addons/point_of_sale/wizard/pos_payment.py
@@ -43,6 +43,7 @@ class pos_make_payment(osv.osv_memory):
         order = order_obj.browse(cr, uid, active_id, context=context)
         amount = order.amount_total - order.amount_paid
         data = self.read(cr, uid, ids, context=context)[0]
+        data['journal'] = data['journal'][0]
 
         if amount != 0.0:
             order_obj.add_payment(cr, uid, active_id, data, context=context)
@@ -74,6 +75,10 @@ class pos_make_payment(osv.osv_memory):
             'datas': datas,
         }
 
+    def _default_journal(self, cr, uid, context=None):
+        res = pos_box_entries.get_journal(self, cr, uid, context=context)
+        return len(res)>1 and res[1] or False
+
     def _default_amount(self, cr, uid, context=None):
         order_obj = self.pool.get('pos.order')
         active_id = context and context.get('active_id', False)
@@ -91,7 +96,8 @@ class pos_make_payment(osv.osv_memory):
     _defaults = {
         'payment_date': time.strftime('%Y-%m-%d %H:%M:%S'),
         'payment_name': _('Payment'),
-        'amount': _default_amount
+        'amount': _default_amount,
+        'journal': _default_journal
     }
 
 pos_make_payment()
-- 
GitLab