[MOD/IMP] point_of_sale: usability improvements

bzr revid: dbr@tinyerp.com-20100714064247-v6zg5w7thhyvjr87
This commit is contained in:
DBR (OpenERP) 2010-07-14 12:12:47 +05:30
parent 7678e0bafc
commit a0f914b4d3
7 changed files with 113 additions and 116 deletions

View File

@ -50,10 +50,8 @@ class pos_company_discount(osv.osv):
'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')),
}
pos_company_discount()
class pos_order(osv.osv):
""" Point of sale gives business owners a convenient way of checking out customers
@ -64,7 +62,6 @@ class pos_order(osv.osv):
_order = "date_order, create_date desc"
_order = "date_order desc"
def unlink(self, cr, uid, ids, context={}):
for rec in self.browse(cr, uid, ids, context=context):
@ -111,7 +108,6 @@ class pos_order(osv.osv):
# Todo need to check this function
""" Find payment Date
@param field_names: Names of fields.
@return: Dictionary of values """
@ -201,8 +197,6 @@ class pos_order(osv.osv):
res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
return res
def _sale_journal_get(self, cr, uid, context):
""" To get sale journal for this order"
@ -324,7 +318,6 @@ class pos_order(osv.osv):
'journal_entry': fields.boolean('Journal Entry'),
}
def _select_pricelist(self, cr, uid, context):
""" To get default pricelist for the order"
@ -367,7 +360,6 @@ class pos_order(osv.osv):
'pricelist_id': _select_pricelist,
}
def test_order_lines(self, cr, uid, order, context={}):
""" Test order line is created or not for the order "
@ -400,12 +392,10 @@ class pos_order(osv.osv):
def _get_qty_differences(self, orders, old_picking):
"""check if the customer changed the product quantity """
order_dict = {}
for order in orders:
for line in order.lines:
order_dict[line.product_id.id] = line
# check the quantity differences:
diff_dict = {}
for line in old_picking.move_lines:
@ -579,7 +569,6 @@ class pos_order(osv.osv):
# cr.execute("Update pos_order set date_validation='%s', state_2 ='%s' where id = %d"%(val, 'accepted', order.id))
# return True
def cancel_order(self, cr, uid, ids, context=None):
""" Changes order state to cancel
@ -687,7 +676,6 @@ class pos_order(osv.osv):
})
clone_list.append(clone_id)
for clone in self.browse(cr, uid, clone_list):
for order_line in clone.lines:
line_obj.write(cr, uid, [order_line.id], {
@ -749,7 +737,6 @@ class pos_order(osv.osv):
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 []
inv_line_ref.create(cr, uid, inv_line, context)
@ -778,7 +765,6 @@ class pos_order(osv.osv):
to_reconcile = []
group_tax = {}
account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context).id
order_account = order.partner_id and order.partner_id.property_account_receivable and order.partner_id.property_account_receivable.id or account_def or curr_c.account_receivable.id
# Create an entry for the sale
@ -827,7 +813,6 @@ class pos_order(osv.osv):
'account defined for this product: "%s" (id:%d)') \
% (line.product_id.name, line.product_id.id, ))
# Empty the tax list as long as there is no tax code:
tax_code_id = False
tax_amount = 0
@ -889,7 +874,6 @@ class pos_order(osv.osv):
'tax_amount': tax_amount,
}, context=context)
# Create a move for each tax group
(tax_code_pos, base_code_pos, account_pos)= (0, 1, 2)
for key, amount in group_tax.items():
@ -926,7 +910,6 @@ class pos_order(osv.osv):
'period_id': period,
}, context=context))
# search the account receivable for the payments:
account_receivable = order.sale_journal.default_credit_account_id.id
if not account_receivable:
@ -964,7 +947,6 @@ class pos_order(osv.osv):
'statement_id': False,
'account_id':order_account
})
self.write(cr,uid,order.id,{'state':'done'})
return True
@ -974,7 +956,6 @@ class pos_order(osv.osv):
self.pool.get('stock.picking').unlink(cr, uid, [picking.id], context)
return True
def action_payment(self, cr, uid, ids, context=None):
vals = {'state': 'payment'}
sequence_obj=self.pool.get('ir.sequence')
@ -1073,11 +1054,10 @@ class pos_order_line(osv.osv):
else:
res[line.id]=line.price_unit*line.qty
res[line.id] = res[line.id] + tax_amount
return res
def _amount_line(self, cr, uid, ids, field_name, arg, context):
res = {}
for line in self.browse(cr, uid, ids):
price = self.price_by_product(cr, uid, ids, line.order_id.pricelist_id.id, line.product_id.id, line.qty, line.order_id.partner_id.id)
if line.discount!=0.0:
@ -1108,7 +1088,8 @@ class pos_order_line(osv.osv):
def onchange_product_id(self, cr, uid, ids, pricelist, product_id, qty=0, partner_id=False):
price = self.price_by_product(cr, uid, ids, pricelist, product_id, qty, partner_id)
self.write(cr,uid,ids,{'price_unit':price})
return {'value': {'price_unit': price}, 'qty': 1}
pos_stot = (price * qty)
return {'value': {'price_unit': price,'price_subtotal_incl': pos_stot}}
def onchange_subtotal(self, cr, uid, ids, discount, price, pricelist,qty,partner_id, product_id,*a):
prod_obj = self.pool.get('product.product')
@ -1122,6 +1103,11 @@ class pos_order_line(osv.osv):
return {'value':{'discount':disc, 'price_unit':price_f}}
return {}
def onchange_dis(self, cr, uid,ids, qty, price_subtotal_incl, discount,*a):
price_sub = price_subtotal_incl
sub_total_discount = price_sub-(price_subtotal_incl*(discount*0.01))
return {'value': {'price_subtotal_incl':sub_total_discount}}
def onchange_ded(self, cr, uid,ids, val_ded,price_u,*a):
pos_order = self.pool.get('pos.order.line')
res_obj = self.pool.get('res.users')
@ -1139,6 +1125,7 @@ class pos_order_line(osv.osv):
res_obj = self.pool.get('res.users')
res_company = self.pool.get('res.company')
company_disc = pos_order.browse(cr,uid,ids)
if discount:
if not company_disc:
comp=res_obj.browse(cr,uid,uid).company_id.company_discount or 0.0
@ -1150,7 +1137,7 @@ class pos_order_line(osv.osv):
else:
return {'value': {'notice':'Minimum Discount','price_ded':price*discount*0.01 or 0.0 }}
else :
return {'value': {'notice':'No Discount', 'price_ded':price*discount*0.01 or 0.0 }}
return {'value': {'notice':'No Discount', 'price_ded':price*discount*0.01 or 0.0}}
_columns = {
'name': fields.char('Line Description', size=512),
'company_id':fields.many2one('res.company', 'Company', required=True),
@ -1214,7 +1201,6 @@ class pos_order_line(osv.osv):
product = self.pool.get('product.product').read(cr, uid, product_id)
product_name = product[0]['name']
price = self.price_by_product(cr, uid, 0, pricelist_id[0]['pricelist_id'][0], product_id[0], 1)
order_line_ids = self.search(cr, uid, [('name','=',product_name),('order_id','=',order)])
if order_line_ids:
new_line = False
@ -1246,7 +1232,6 @@ class pos_order_line(osv.osv):
pos_order_line()
class pos_payment(osv.osv):
_name = 'pos.payment'
_description = 'Pos Payment'
@ -1314,7 +1299,6 @@ class account_move_line(osv.osv):
account_move_line()
class account_move(osv.osv):
_inherit = 'account.move'

View File

@ -22,19 +22,20 @@
<field name="lines" colspan="4" nolabel="1">
<tree string="Order lines" editable="bottom">
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,qty,parent.partner_id)" width="275" />
<field name="qty" />
<field name="qty"/>
<!--<field name="qty" on_change="onchange_qty(qty,price_unit)"/>-->
<!--field name="qty_rfd" groups="base.group_extended"/-->
<field name="discount" on_change="onchange_discount(discount,price_unit)" />
<field name="price_ded" on_change="onchange_ded(price_ded, price_unit)" invisible="1"/>
<field name="price_ded" on_change="onchange_ded(price_ded, price_subtotal_incl,price_unit)" invisible="1"/>
<field name="price_unit" readonly="1"/>
<field name="notice"/>
<field name="notice" on_change="onchange_dis(qty,price_subtotal_incl,discount)"/>
<!--field name="serial_number"/-->
<field name="price_subtotal" />
<field name="price_subtotal_incl" sum="Subtotal"/>
</tree>
<form string="Order lines" >
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,qty,parent.partner_id)" width="275"/>
<field name="qty" />
<field name="qty"/>
<field name="qty_rfd" groups="base.group_extended"/>
<field name="discount" on_change="onchange_discount(discount,price_unit)" />
<field name="price_ded" on_change="onchange_ded(price_ded, price_unit)" />
@ -64,7 +65,7 @@
<!-- </group>-->
<separator colspan="4" string="Actions"/>
<group colspan="4" col="6">
<field name="state"/>
<field name="state" />
<button name="%(action_pos_payment)d" string="Ma_ke Payment" icon="gtk-ok" type="action" states="draft,advance" />
<button name="%(action_report_pos_receipt)d" string="_Reprint" icon="gtk-print" type="action" states="paid,done,invoiced"/>
<button name="set_to_draft" string="Set to draft" states="paid" icon="gtk-execute" type="object" />

View File

@ -90,8 +90,6 @@ class report_pos_order(osv.osv):
to_char(s.date_order, 'dd-MM-YYYY'),to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),
to_char(s.date_order, 'YYYY-MM-DD'), s.partner_id,s.state,
s.user_id,s.shop_id,s.company_id,s.sale_journal,l.product_id,s.date_validation,
s.date_payment
)
""")
s.date_payment)""")
report_pos_order()

View File

@ -15,7 +15,7 @@
<field name="partner_id" invisible="1"/>
<field name="product_id" invisible="1"/>
<field name="shop_id" invisible="1"/>
<field name="journal_id" invisible="1"/>
<!--<field name="journal_id" invisible="1"/>-->
<field name="date_validation" invisible="1"/>
<field name="date_payment" invisible="1"/>
<field name="company_id" invisible="1" groups="base.group_multi_company"/>
@ -26,7 +26,7 @@
<field name="price_total" sum="Total Price"/>
<field name="delay_validation"/>
<field name="delay_payment"/>
<field name="state" invisible="1"/>
<!--<field name="state" invisible="1"/>-->
</tree>
</field>
</record>
@ -78,10 +78,9 @@
<filter string="Customer" icon="terp-personal" context="{'group_by':'partner_id'}"/>
<separator orientation="vertical"/>
<filter string="Product" icon="terp-accessories-archiver" context="{'group_by':'product_id'}"/>
<filter string="Journal" icon="terp-folder-orange" context="{'group_by':'journal_id'}"/>
<!--<filter string="Journal" icon="terp-folder-orange" context="{'group_by':'journal_id'}"/>-->
<separator orientation="vertical"/>
<filter string="State" icon="terp-stock_effects-object-colorize" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<!--<filter string="State" icon="terp-stock_effects-object-colorize" context="{'group_by':'state'}"/>-->
<filter string="Day" icon="terp-go-today" context="{'group_by':'day'}"/>
<filter string="Month" icon="terp-go-month" context="{'group_by':'month'}"/>
<filter string="Year" icon="terp-go-year" context="{'group_by':'year'}"/>
@ -106,4 +105,4 @@
<menuitem action="action_report_pos_order_all" id="menu_report_pos_order_all" parent="menu_point_rep" sequence="1"/>
</data>
</openerp>
</openerp>

View File

@ -35,14 +35,16 @@ def get_journal(self, cr, uid, context):
"""
obj = self.pool.get('account.journal')
statement_obj = self.pool.get('account.bank.statement')
user = self.pool.get('res.users').browse(cr, uid, uid)
ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', user.company_id.id)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
obj_ids= statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', 'in', ids)])
res_obj = obj.read(cr, uid, ids, ['journal_id'], context)
res_obj = [(r1['id'])for r1 in res_obj]
res = statement_obj.read(cr, uid, obj_ids, ['journal_id'], context)
res = [(r['journal_id']) for r in res]
return res
class pos_box_entries(osv.osv_memory):
_name = 'pos.box.entries'
_description = 'Pos Box Entries'
@ -62,7 +64,7 @@ class pos_box_entries(osv.osv_memory):
obj = self.pool.get('product.product')
ids = obj.search(cr, uid, [('income_pdt', '=', True)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
res = [(r['id'],r['name']) for r in res]
res.insert(0, ('', ''))
return res

View File

@ -22,7 +22,6 @@
from osv import osv
from tools.translate import _
class pos_close_statement(osv.osv_memory):
_name = 'pos.close.statement'
_description = 'Close Statements'
@ -41,18 +40,35 @@ class pos_close_statement(osv.osv_memory):
mod_obj = self.pool.get('ir.model.data')
statement_obj = self.pool.get('account.bank.statement')
journal_obj = self.pool.get('account.journal')
journal_lst = journal_obj.search(cr, uid, [('company_id', '=', company_id), ('auto_cash', '=', True)])
journal_ids = journal_obj.browse(cr, uid, journal_lst)
list_statement=[]
user_obj="""select DISTINCT journal_id from pos_journal_users where user_id=%d"""%(uid)
cr.execute(user_obj)
user_journals1= cr.fetchall()
lst1=map(lambda x1:x1[0],user_journals1)
journal_ids = journal_obj.browse(cr, uid, lst1)
for journal in journal_ids:
ids = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', '=', journal.id)])
list_statement.append(ids[0])
if not journal.check_dtls:
statement_obj.button_confirm(cr, uid, ids, context)
# if not list_statement:
# return {}
# model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_bank_statement_tree')], context=context)
# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
sql = """ select id from account_journal
where auto_cash = 'True'
and company_id =%d and id =%d"""%(company_id,journal.id)
cr.execute(sql)
user_journals= cr.fetchall()
lst=map(lambda x1:x1[0],user_journals)
journal_ids1 = journal_obj.browse(cr, uid, lst)
#list_statement=[]
for journal1 in journal_ids1:
ids = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', '=', journal.id)])
if not ids:
raise osv.except_osv(_('Message'), _('Journals are allready closed'))
else:
list_statement.append(ids[0])
if not journal.check_dtls:
statement_obj.button_confirm_bank(cr, uid, ids, context)
# if not list_statement:
# return {}
# model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_bank_statement_tree')], context=context)
# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
data_obj = self.pool.get('ir.model.data')
id2 = data_obj._get_id(cr, uid, 'account', 'view_bank_statement_tree')
@ -61,7 +77,6 @@ class pos_close_statement(osv.osv_memory):
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
return {
'domain': "[('id','in'," + str(list_statement) + ")]",
'name': 'Close Statements',
@ -69,10 +84,8 @@ class pos_close_statement(osv.osv_memory):
'view_mode': 'tree,form',
'res_model': 'account.bank.statement',
'views': [(id2, 'tree'),(id3, 'form')],
'type': 'ir.actions.act_window'
}
'type': 'ir.actions.act_window'}
pos_close_statement()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -23,7 +23,6 @@ from osv import osv
from tools.translate import _
import time
class pos_open_statement(osv.osv_memory):
_name = 'pos.open.statement'
_description = 'Open Statements'
@ -44,63 +43,67 @@ class pos_open_statement(osv.osv_memory):
singer_obj = self.pool.get('singer.statement')
sequence_obj = self.pool.get('ir.sequence')
journal_obj = self.pool.get('account.journal')
journal_lst = journal_obj.search(cr, uid, [('company_id', '=', company_id), ('auto_cash', '=', True)])
sql = """
select journal_id from pos_journal_users
where user_id=%d
"""%(uid)
cr.execute(sql)
user_journals = cr.fetchall()
lst = map(lambda x: x[0], user_journals)
journal_ids = journal_obj.browse(cr, uid, lst)
user_obj="""select DISTINCT journal_id from pos_journal_users where user_id=%d"""%(uid)
cr.execute(user_obj)
user_journals1= cr.fetchall()
lst1=map(lambda x1:x1[0],user_journals1)
journal_ids = journal_obj.browse(cr, uid, lst1)
for journal in journal_ids:
ids = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', '=', journal.id)])
if len(ids):
raise osv.except_osv(_('Message'), _('You can not open a Cashbox for "%s". \n Please close the cashbox related to. ' % (journal.name)))
sql = """ Select id from account_bank_statement
where journal_id=%d
and company_id =%d
order by id desc limit 1""" % (journal.id, company_id)
sql = """ select id from account_journal
where auto_cash = 'True'
and company_id =%d and id =%d"""%(company_id,journal.id)
cr.execute(sql)
st_id = cr.fetchone()
number = ''
if journal.sequence_id:
number = sequence_obj.get_id(cr, uid, journal.id)
else:
number = sequence_obj.get(cr, uid,
'account.bank.statement')
user_journals= cr.fetchall()
lst=map(lambda x1:x1[0],user_journals)
journal_ids1 = journal_obj.browse(cr, uid, lst)
statement_id=statement_obj.create(cr,uid,{'journal_id':journal.id,
'company_id':company_id,
'user_id':uid,
'state':'open',
'name':number
})
statement_obj.button_open(cr,uid,[statement_id],context)
# period = statement_obj._get_period(cr, uid, context) or None
# cr.execute("INSERT INTO account_bank_statement(journal_id,company_id,user_id,state,name, period_id,date) VALUES(%d,%d,%d,'open','%s',%d,'%s')"%(journal.id, company_id, uid, number, period, time.strftime('%Y-%m-%d %H:%M:%S')))
# cr.commit()
# cr.execute("select id from account_bank_statement where journal_id=%d and company_id=%d and user_id=%d and state='open' and name='%s'"%(journal.id, company_id, uid, number))
# statement_id = cr.fetchone()[0]
# print "statement_id",statement_id
# if st_id:
# statemt_id = statement_obj.browse(cr, uid, st_id[0])
# list_statement.append(statemt_id.id)
# if statemt_id and statemt_id.ending_details_ids:
# statement_obj.write(cr, uid, [statement_id], {
# 'balance_start': statemt_id.balance_end,
# 'state': 'open',
# })
# if statemt_id.ending_details_ids:
# for i in statemt_id.ending_details_ids:
# c = statement_obj.create(cr, uid, {
# 'pieces': i.pieces,
# 'number': i.number,
# 'starting_id': statement_id,
# })
for journal1 in journal_ids1:
ids1 = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', '=', journal.id)])
if len(ids):
raise osv.except_osv(_('Message'), _('You can not open a Cashbox for "%s". \n Please close the cashbox related to. ' %(journal.name)))
sql = """ Select id from account_bank_statement
where journal_id =%d
and company_id =%d
order by id desc limit 1""" %(journal.id, company_id)
cr.execute(sql)
st_id = cr.fetchone()
number = ''
if journal.sequence_id:
number = sequence_obj.get_id(cr, uid, journal.id)
else:
number = sequence_obj.get(cr, uid,
'account.bank.statement')
statement_id=statement_obj.create(cr,uid,{'journal_id':journal.id,
'company_id':company_id,
'user_id':uid,
'state':'open',
'name':number
})
statement_obj.button_open(cr,uid,[statement_id],context)
# period = statement_obj._get_period(cr, uid, context) or None
# cr.execute("INSERT INTO account_bank_statement(journal_id,company_id,user_id,state,name, period_id,date) VALUES(%d,%d,%d,'open','%s',%d,'%s')"%(journal.id, company_id, uid, number, period, time.strftime('%Y-%m-%d %H:%M:%S')))
# cr.commit()
# cr.execute("select id from account_bank_statement where journal_id=%d and company_id=%d and user_id=%d and state='open' and name='%s'"%(journal.id, company_id, uid, number))
# statement_id = cr.fetchone()[0]
# print "statement_id",statement_id
# if st_id:
# statemt_id = statement_obj.browse(cr, uid, st_id[0])
# list_statement.append(statemt_id.id)
# if statemt_id and statemt_id.ending_details_ids:
# statement_obj.write(cr, uid, [statement_id], {
# 'balance_start': statemt_id.balance_end,
# 'state': 'open',
# })
# if statemt_id.ending_details_ids:
# for i in statemt_id.ending_details_ids:
# c = statement_obj.create(cr, uid, {
# 'pieces': i.pieces,
# 'number': i.number,
# 'starting_id': statement_id,
# })
data_obj = self.pool.get('ir.model.data')
id2 = data_obj._get_id(cr, uid, 'account', 'view_bank_statement_tree')
id3 = data_obj._get_id(cr, uid, 'account', 'view_bank_statement_form2')
@ -110,7 +113,7 @@ class pos_open_statement(osv.osv_memory):
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
return {
# 'domain': "[('id','in', ["+','.join(map(str,list_statement))+"])]",
# 'domain': "[('id','in', ["+','.join(map(str,list_statement))+"])]",
'domain': "[('state','=','open')]",
'name': 'Open Statement',
'view_type': 'form',
@ -119,9 +122,6 @@ class pos_open_statement(osv.osv_memory):
'views': [(id2, 'tree'),(id3, 'form')],
'type': 'ir.actions.act_window'
}
# return {}
pos_open_statement()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: