[IMP] fix code rules and simple improvements in POS
authorCristian Salamea <ovnicraft@gmail.com>
Fri, 5 Nov 2010 01:29:52 +0000 (20:29 -0500)
committerCristian Salamea <ovnicraft@gmail.com>
Fri, 5 Nov 2010 01:29:52 +0000 (20:29 -0500)
bzr revid: ovnicraft@gmail.com-20101105012952-6cqvt5iaxty5be3k

addons/point_of_sale/point_of_sale.py
addons/point_of_sale/point_of_sale_view.xml
addons/point_of_sale/wizard/pos_add_product.py
addons/point_of_sale/wizard/pos_scan_product.py

index 6764add..80b5a86 100644 (file)
@@ -33,6 +33,7 @@ class pos_config_journal(osv.osv):
     """ Point of Sale journal configuration"""
     _name = 'pos.config.journal'
     _description = "Journal Configuration"
+    
     _columns = {
         'name': fields.char('Description', size=64),
         'code': fields.char('Code', size=64),
@@ -41,9 +42,11 @@ class pos_config_journal(osv.osv):
 
 pos_config_journal()
 
+
 class pos_company_discount(osv.osv):
     """ Company Discount and Cashboxes """
     _inherit = 'res.company'
+    
     _columns = {
         'company_discount': fields.float('Max Discount(%)', digits_compute=dp.get_precision('Point Of Sale')),
         'max_diff': fields.float('Max Difference for Cashboxes', digits_compute=dp.get_precision('Point Of Sale Discount')),
@@ -106,10 +109,10 @@ class pos_order(osv.osv):
         val = None
         for order in self.browse(cr, uid, ids):
             cr.execute("SELECT date_payment FROM pos_order WHERE id = %s", (order.id,))
-            date_p=cr.fetchone()
-            date_p=date_p and date_p[0] or None
+            date_p = cr.fetchone()
+            date_p = date_p and date_p[0] or None
             if date_p:
-                res[order.id]=date_p
+                res[order.id] = date_p
                 return res
             cr.execute(" SELECT MAX(l.date) "
                         " FROM account_move_line l, account_move m, account_invoice i, account_move_reconcile r, pos_order o "
@@ -173,20 +176,22 @@ class pos_order(osv.osv):
                             (1-(line.discount or 0.0)/100.0), line.qty),
                             res[order.id]['amount_tax'])
                 elif line.qty != 0.0:
-                    for c in tax_obj.compute_all(cr, uid, line.product_id.taxes_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.qty,  line.product_id, line.order_id.partner_id)['taxes']:
+                    for c in tax_obj.compute_all(cr, uid, line.product_id.taxes_id, \
+                                                 line.price_unit * (1-(line.discount or 0.0)/100.0), \
+                                                 line.qty,  line.product_id, line.order_id.partner_id)['taxes']:
                         val += c.get('amount', 0.0)
                     res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
         return res
 
     def _sale_journal_get(self, cr, uid, context=None):
-        """ To get  sale journal for this order"
+        """ To get  sale journal for this order
         @return: journal  """
         journal_obj = self.pool.get('account.journal')
         res = journal_obj.search(cr, uid, [('type', '=', 'sale')], limit=1)
         return res and res[0] or False
 
     def _shop_get(self, cr, uid, context=None):
-        """ To get  Shop  for this order"
+        """ To get  Shop  for this order
         @return: Shop id  """
         res = self.pool.get('sale.shop').search(cr, uid, [])
         return res and res[0] or False
@@ -206,7 +211,7 @@ class pos_order(osv.osv):
         })
         return super(pos_order, self).copy(cr, uid, id, default, context=context)
 
-    def _get_v( self, cr, uid, ids, *a):
+    def _get_v( self, cr, uid, ids, *args):
         """ Changed the Validation state of order
         @return: State  """
         res_obj = self.pool.get('res.users')
@@ -242,8 +247,13 @@ class pos_order(osv.osv):
         'shop_id': fields.many2one('sale.shop', 'Shop', required=True,
             states={'draft': [('readonly', False)]}, readonly=True),
         'date_order': fields.datetime('Date Ordered', readonly=True),
-        'date_validation': fields.function(_get_date_payment, method=True, string='Validation Date', type='date', store=True),
-        'date_payment': fields.function(_get_date_payment2, method=True, string='Payment Date', type='date', store=True),
+        'date_validation': fields.function(_get_date_payment,
+                                           method=True,
+                                           string='Validation Date',
+                                           type='date', store=True),
+        'date_payment': fields.function(_get_date_payment2, method=True,
+                                        string='Payment Date',
+                                        type='date', store=True),
         'date_validity': fields.date('Validity Date', required=True),
         'user_id': fields.many2one('res.users', 'Connected Salesman', help="Person who uses the the cash register. It could be a reliever, a student or an interim employee."),
         'user_salesman_id': fields.many2one('res.users', 'Cashier', required=True, help="User who is logged into the system."),
@@ -285,7 +295,7 @@ class pos_order(osv.osv):
 
 
     def _select_pricelist(self, cr, uid, context=None):
-        """ To get default pricelist for the order"
+        """ To get default pricelist for the order
         @param name: Names of fields.
         @return: pricelist ID
         """
@@ -293,7 +303,7 @@ class pos_order(osv.osv):
         return pricelist and pricelist[0] or False
 
     def _journal_default(self, cr, uid, context=None):
-        """ To get default pricelist for the order"
+        """ To get default pricelist for the order
         @param name: Names of fields.
         @return: journal ID
         """
@@ -319,7 +329,7 @@ class pos_order(osv.osv):
 
 
     def test_order_lines(self, cr, uid, order, context=None):
-        """ Test order line is created or not for the order "
+        """ Test order line is created or not for the order 
         @param name: Names of fields.
         @return: True
         """
@@ -452,7 +462,7 @@ class pos_order(osv.osv):
                         location_id, stock_dest_id = stock_dest_id, location_id
 
                     move_obj.create(cr, uid, {
-                            'name': 'Stock move (POS %d)' % (order.id, ),
+                            'name': '(POS %d)' % (order.id, ),
                             'product_uom': line.product_id.uom_id.id,
                             'product_uos': line.product_id.uom_id.id,
                             'picking_id': picking_id,
@@ -507,7 +517,7 @@ class pos_order(osv.osv):
 
     def add_payment(self, cr, uid, order_id, data, context=None):
         """Create a new payment for the order"""
-        statement_obj= self.pool.get('account.bank.statement')
+        statement_obj = self.pool.get('account.bank.statement')
         statement_line_obj = self.pool.get('account.bank.statement.line')
         prod_obj = self.pool.get('product.product')
         property_obj = self.pool.get('ir.property')
@@ -525,12 +535,15 @@ class pos_order(osv.osv):
         if 'payment_name' in data.keys():
             args['name'] = data['payment_name'] + ' ' + order.name
         account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context)
-        args['account_id'] = order.partner_id and order.partner_id.property_account_receivable and order.partner_id.property_account_receivable.id or account_def.id or curr_c.account_receivable.id
+        args['account_id'] = order.partner_id and order.partner_id.property_account_receivable \
+                             and order.partner_id.property_account_receivable.id or account_def.id or curr_c.account_receivable.id
         if data.get('is_acc', False):
             args['is_acc'] = data['is_acc']
-            args['account_id'] = prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income and prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income.id
+            args['account_id'] = prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income \
+                                 and prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income.id
             if not args['account_id']:
-                raise osv.except_osv(_('Error'), _('Please provide an account for the product: %s')%(prod_obj.browse(cr, uid, data['product_id'], context=context).name))
+                raise osv.except_osv(_('Error'), _('Please provide an account for the product: %s')% \
+                                     (prod_obj.browse(cr, uid, data['product_id'], context=context).name))
         args['partner_id'] = order.partner_id and order.partner_id.id or None
         args['ref'] = order.contract_number or None
 
@@ -546,6 +559,8 @@ class pos_order(osv.osv):
         args['statement_id'] = statement_id
         args['pos_statement_id'] = order_id
         args['journal_id'] = data['journal']
+        args['type'] = 'customer'
+        args['ref'] = order.name
         statement_line_obj.create(cr, uid, args, context=context)
         ids_new.append(statement_id)
 
@@ -556,7 +571,9 @@ class pos_order(osv.osv):
         return statement_id
 
     def add_product(self, cr, uid, order_id, product_id, qty, context=None):
+        
         """Create a new order line the order"""
+        
         line_obj = self.pool.get('pos.order.line')
         values = self.read(cr, uid, order_id, ['partner_id', 'pricelist_id'])
 
@@ -577,7 +594,9 @@ class pos_order(osv.osv):
         return order_line_id, price
 
     def refund(self, cr, uid, ids, context=None):
+        
         """Create a copy of order  for refund order"""
+        
         clone_list = []
         line_obj = self.pool.get('pos.order.line')
 
@@ -602,7 +621,9 @@ class pos_order(osv.osv):
         return clone_list
 
     def action_invoice(self, cr, uid, ids, context=None):
+        
         """Create a invoice of order  """
+        
         inv_ref = self.pool.get('account.invoice')
         inv_line_ref = self.pool.get('account.invoice.line')
         product_obj = self.pool.get('product.product')
@@ -645,10 +666,10 @@ class pos_order(osv.osv):
                 inv_line.update(inv_line_ref.product_id_change(cr, uid, [],
                                                                line.product_id.id,
                                                                line.product_id.uom_id.id,
-                                                               line.qty, partner_id = order.partner_id.id, fposition_id=order.partner_id.property_account_position.id)['value'])
+                                                               line.qty, partner_id = order.partner_id.id,
+                                                               fposition_id=order.partner_id.property_account_position.id)['value'])
                 inv_line['price_unit'] = line.price_unit
                 inv_line['discount'] = line.discount
-                inv_line['account_id'] = acc
                 inv_line['name'] = inv_name
                 inv_line['invoice_line_tax_id'] = ('invoice_line_tax_id' in inv_line)\
                     and [(6, 0, inv_line['invoice_line_tax_id'])] or []
index 4d277d2..56e26c7 100644 (file)
@@ -17,6 +17,8 @@
                         <field name="shop_id" widget="selection"/>
                         <field name="partner_id" on_change="onchange_partner_pricelist(partner_id)"/>
                         <field name="contract_number" groups="base.group_extended"/>
+                       <button name="%(point_of_sale.action_pos_scan_product)d" string="Scan Barcode" type="action" states="draft,advance"/>
+                       <button name="%(point_of_sale.action_add_product)d" string="Add Product" type="action" states="draft,advance"/>
                     </group>
                     <notebook colspan="4">
                         <page string="Sale Order">
index 601c3d3..c53539d 100644 (file)
@@ -78,19 +78,17 @@ class add_product(osv.osv_memory):
         order_obj= self.pool.get('pos.order')
         obj = order_obj.browse(cr, uid, record_id, context=context)
         order_obj.write(cr, uid, [record_id], {'state': 'done'}, context=context)
-        if obj.amount_total != obj.amount_paid:
-            return {
-                'name': _('Make Payment'),
-                'context': context and context.get('active_id', False),
-                'view_type': 'form',
-                'view_mode': 'form',
-                'res_model': 'pos.make.payment',
-                'view_id': False,
+        return {
+            'name': _('Make Payment'),
+            'context': context and context.get('active_id', False),
+            'view_type': 'form',
+            'view_mode': 'form',
+            'res_model': 'pos.make.payment',
+            'view_id': False,
                 'target': 'new',
-                'views': False,
-                'type': 'ir.actions.act_window',
-            }
-        return {}
+            'views': False,
+            'type': 'ir.actions.act_window',
+        }
 
 add_product()
 
index debfe3b..93ae400 100644 (file)
@@ -25,9 +25,11 @@ from tools.translate import _
 class pos_scan_product(osv.osv_memory):
     _name = 'pos.scan.product'
     _description = 'Scan product'
+    
     _columns = {
-        'gencod': fields.char('Barcode',size=13,required= True)
+        'gencod': fields.char('Barcode', size=13, required=True)
     }
+    
     def scan(self, cr, uid, ids, context):
         """ 
          To get the gencod and scan product         
@@ -38,10 +40,11 @@ class pos_scan_product(osv.osv_memory):
          @return : retrun gencod
         """
                 
-        data=self.read(cr, uid, ids)[0]
-        record_id = context and context.get('active_id',False)
+        data = self.read(cr, uid, ids)[0]
+        record_id = context and context.get('active_id', False)
         result =self. pool.get('pos.order.line')._scan_product(cr, uid, data['gencod'], 1, record_id)
         return {'gencod': False}
+
 pos_scan_product()
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: