[IMP] point_of_sale: code cleaning
bzr revid: psi@tinyerp.co.in-20101026130012-olfktqj5qr578lpb
This commit is contained in:
parent
68dc715dfa
commit
09badf3375
|
@ -52,7 +52,7 @@ class pos_box_entries(osv.osv_memory):
|
|||
_name = 'pos.box.entries'
|
||||
_description = 'Pos Box Entries'
|
||||
|
||||
def _get_income_product(self, cr, uid, context):
|
||||
def _get_income_product(self, cr, uid, context=None):
|
||||
"""
|
||||
Make the selection list of purchasing products.
|
||||
@param self: The object pointer.
|
||||
|
@ -61,10 +61,10 @@ class pos_box_entries(osv.osv_memory):
|
|||
@param context: A standard dictionary
|
||||
@return :Return of operation of product
|
||||
"""
|
||||
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]
|
||||
product_obj = self.pool.get('product.product')
|
||||
ids = product_obj.search(cr, uid, [('income_pdt', '=', True)], context=context)
|
||||
res = product_obj.read(cr, uid, ids, ['id', 'name'], context=context)
|
||||
res = [(r['id'], r['name']) for r in res]
|
||||
res.insert(0, ('', ''))
|
||||
|
||||
return res
|
||||
|
@ -72,17 +72,17 @@ class pos_box_entries(osv.osv_memory):
|
|||
|
||||
_columns = {
|
||||
'name': fields.char('Description', size=32, required=True),
|
||||
'journal_id': fields.selection(get_journal, "Register", required=True),
|
||||
'product_id': fields.selection(_get_income_product, "Operation", required=True),
|
||||
'journal_id': fields.selection(get_journal, 'Register', required=True),
|
||||
'product_id': fields.selection(_get_income_product, 'Operation', required=True),
|
||||
'amount': fields.float('Amount', digits=(16, 2)),
|
||||
'ref': fields.char('Ref', size=32),
|
||||
}
|
||||
_defaults = {
|
||||
'journal_id': lambda *a: 1,
|
||||
'product_id': lambda *a: 1,
|
||||
'journal_id': 1,
|
||||
'product_id': 1,
|
||||
}
|
||||
|
||||
def get_in(self, cr, uid, ids, context):
|
||||
def get_in(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Create the entry of statement in journal.
|
||||
@param self: The object pointer.
|
||||
|
@ -92,14 +92,13 @@ class pos_box_entries(osv.osv_memory):
|
|||
@return :Return of operation of product
|
||||
"""
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
product_obj = self.pool.get('product.template')
|
||||
res_obj = self.pool.get('res.users')
|
||||
product_obj = self.pool.get('product.product')
|
||||
bank_statement = self.pool.get('account.bank.statement.line')
|
||||
for data in self.read(cr, uid, ids):
|
||||
args = {}
|
||||
curr_company = res_obj.browse(cr, uid, uid).company_id.id
|
||||
statement_id = statement_obj.search(cr, uid, [('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')])
|
||||
for data in self.read(cr, uid, ids, context=context):
|
||||
vals = {}
|
||||
curr_company = res_obj.browse(cr, uid, uid, context=context).company_id.id
|
||||
statement_id = statement_obj.search(cr, uid, [('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')], context=context)
|
||||
if not statement_id:
|
||||
raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
|
||||
|
||||
|
@ -114,22 +113,20 @@ class pos_box_entries(osv.osv_memory):
|
|||
'journal_id': data['journal_id'],
|
||||
'company_id': curr_company,
|
||||
'user_id': uid,
|
||||
})
|
||||
}, context=context)
|
||||
|
||||
args['statement_id'] = statement_id
|
||||
args['journal_id'] = data['journal_id']
|
||||
vals['statement_id'] = statement_id
|
||||
valss['journal_id'] = data['journal_id']
|
||||
if acc_id:
|
||||
args['account_id'] = acc_id.id
|
||||
args['amount'] = data['amount'] or 0.0
|
||||
args['ref'] = "%s" % (data['ref'] or '')
|
||||
args['name'] = "%s: %s " % (product_obj.browse(cr, uid, data['product_id']).name, data['name'].decode('utf8'))
|
||||
address_u = res_obj.browse(cr, uid, uid).address_id
|
||||
vals['account_id'] = acc_id.id
|
||||
vals['amount'] = data['amount'] or 0.0
|
||||
vals['ref'] = "%s" % (data['ref'] or '')
|
||||
vals['name'] = "%s: %s " % (product_obj.browse(cr, uid, data['product_id'], context=context).name, data['name'].decode('utf8'))
|
||||
address_u = res_obj.browse(cr, uid, uid, context=context).address_id
|
||||
if address_u:
|
||||
partner_id = address_u.partner_id and address_u.partner_id.id or None
|
||||
args['partner_id'] = partner_id
|
||||
bank_statement.create(cr, uid, args)
|
||||
|
||||
return {}
|
||||
vals['partner_id'] = address_u.partner_id and address_u.partner_id.id or None
|
||||
bank_statement.create(cr, uid, vals, context=context)
|
||||
return {}
|
||||
|
||||
pos_box_entries()
|
||||
|
||||
|
|
|
@ -19,20 +19,19 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
import time
|
||||
from tools.translate import _
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import pos_box_entries
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
import pos_box_entries
|
||||
|
||||
class pos_box_out(osv.osv_memory):
|
||||
_name = 'pos.box.out'
|
||||
_description = 'Pos Box Out'
|
||||
|
||||
def _get_expense_product(self, cr, uid, context):
|
||||
|
||||
def _get_expense_product(self, cr, uid, context=None):
|
||||
"""
|
||||
Make the selection list of expense product.
|
||||
@param self: The object pointer.
|
||||
|
@ -41,26 +40,26 @@ class pos_box_out(osv.osv_memory):
|
|||
@param context: A standard dictionary
|
||||
@return :Return of operation of product
|
||||
"""
|
||||
obj = self.pool.get('product.product')
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
|
||||
ids = obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)])
|
||||
res = obj.read(cr, uid, ids, ['id', 'name'], context)
|
||||
product_obj = self.pool.get('product.product')
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
|
||||
ids = product_obj.search(cr, uid, ['&', ('expense_pdt', '=', True), '|', ('company_id', '=', company_id), ('company_id', '=', None)], context=context)
|
||||
res = product_obj.read(cr, uid, ids, ['id', 'name'], context=context)
|
||||
res = [(r['id'], r['name']) for r in res]
|
||||
res.insert(0, ('', ''))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Description', size=32, required=True),
|
||||
'journal_id': fields.selection(pos_box_entries.get_journal, "Register", required=True),
|
||||
'product_id': fields.selection(_get_expense_product, "Operation", required=True),
|
||||
'journal_id': fields.selection(pos_box_entries.get_journal, 'Register', required=True),
|
||||
'product_id': fields.selection(_get_expense_product, 'Operation', required=True),
|
||||
'amount': fields.float('Amount', digits=(16, 2)),
|
||||
'ref': fields.char('Ref', size=32),
|
||||
}
|
||||
_defaults = {
|
||||
'journal_id': lambda *a: 1,
|
||||
'product_id': lambda *a: 1,
|
||||
'journal_id': 1,
|
||||
'product_id': 1,
|
||||
}
|
||||
def get_out(self, cr, uid, ids, context):
|
||||
def get_out(self, cr, uid, ids, context=None):
|
||||
|
||||
"""
|
||||
Create the entries in the CashBox .
|
||||
|
@ -70,34 +69,34 @@ class pos_box_out(osv.osv_memory):
|
|||
@param context: A standard dictionary
|
||||
@return :Return of operation of product
|
||||
"""
|
||||
args = {}
|
||||
vals = {}
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
product_obj = self.pool.get('product.template')
|
||||
productp_obj = self.pool.get('product.product')
|
||||
res_obj = self.pool.get('res.users')
|
||||
for data in self.read(cr, uid, ids):
|
||||
curr_company = res_obj.browse(cr, uid, uid).company_id.id
|
||||
statement_id = statement_obj.search(cr, uid, [('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')])
|
||||
for data in self.read(cr, uid, ids, context=context):
|
||||
curr_company = res_obj.browse(cr, uid, uid, context=context).company_id.id
|
||||
statement_id = statement_obj.search(cr, uid, [('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')], context=context)
|
||||
monday = (datetime.today() + relativedelta(weekday=0)).strftime('%Y-%m-%d')
|
||||
sunday = (datetime.today() + relativedelta(weekday=6)).strftime('%Y-%m-%d')
|
||||
done_statmt = statement_obj.search(cr, uid, [('date', '>=', monday+' 00:00:00'), ('date', '<=', sunday+' 23:59:59'), ('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid)])
|
||||
stat_done = statement_obj.browse(cr, uid, done_statmt)
|
||||
address_u = res_obj.browse(cr, uid, uid).address_id
|
||||
done_statmt = statement_obj.search(cr, uid, [('date', '>=', monday+' 00:00:00'), ('date', '<=', sunday+' 23:59:59'), ('journal_id', '=', data['journal_id']), ('company_id', '=', curr_company), ('user_id', '=', uid)], context=context)
|
||||
stat_done = statement_obj.browse(cr, uid, done_statmt, context=context)
|
||||
address_u = res_obj.browse(cr, uid, uid, context=context).address_id
|
||||
am = 0.0
|
||||
|
||||
amount_check = productp_obj.browse(cr, uid, data['product_id']).am_out or False
|
||||
amount_check = productp_obj.browse(cr, uid, data['product_id'], context=context).am_out or False
|
||||
for st in stat_done:
|
||||
for s in st.line_ids:
|
||||
if address_u and s.partner_id == address_u.partner_id and s.am_out:
|
||||
am += s.amount
|
||||
if (-data['amount'] or 0.0) + am < -(res_obj.browse(cr, uid, uid).company_id.max_diff or 0.0) and amount_check:
|
||||
if (-data['amount'] or 0.0) + am < -(res_obj.browse(cr, uid, uid, context=context).company_id.max_diff or 0.0) and amount_check:
|
||||
val = (res_obj.browse(cr, uid, uid).company_id.max_diff or 0.0) + am
|
||||
raise osv.except_osv(_('Error !'), _('The maximum value you can still withdraw is exceeded. \n Remaining value is equal to %d ')%(val))
|
||||
|
||||
acc_id = product_obj.browse(cr, uid, data['product_id']).property_account_income
|
||||
acc_id = product_obj.browse(cr, uid, data['product_id'], context=context).property_account_income
|
||||
if not acc_id:
|
||||
raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr, uid, data['product_id']).name))
|
||||
raise osv.except_osv(_('Error !'), _('please check that account is set to %s')%(product_obj.browse(cr, uid, data['product_id'], context=context).name))
|
||||
if not statement_id:
|
||||
raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox'))
|
||||
if statement_id:
|
||||
|
@ -108,24 +107,23 @@ class pos_box_out(osv.osv_memory):
|
|||
'journal_id': data['journal_id'],
|
||||
'company_id': curr_company,
|
||||
'user_id': uid,
|
||||
})
|
||||
args['statement_id'] = statement_id
|
||||
args['journal_id'] = data['journal_id']
|
||||
}, context=context)
|
||||
vals['statement_id'] = statement_id
|
||||
vals['journal_id'] = data['journal_id']
|
||||
if acc_id:
|
||||
args['account_id'] = acc_id.id
|
||||
vals['account_id'] = acc_id.id
|
||||
amount = data['amount'] or 0.0
|
||||
if data['amount'] > 0:
|
||||
amount = -data['amount']
|
||||
args['amount'] = amount
|
||||
if productp_obj.browse(cr, uid, data['product_id']).am_out:
|
||||
args['am_out'] = True
|
||||
args['ref'] = data['ref'] or ''
|
||||
args['name'] = "%s: %s " % (product_obj.browse(cr, uid, data['product_id']).name, data['name'].decode('utf8'))
|
||||
address_u = res_obj.browse(cr, uid, uid).address_id
|
||||
vals['amount'] = amount
|
||||
if productp_obj.browse(cr, uid, data['product_id'], context=context).am_out:
|
||||
vals['am_out'] = True
|
||||
vals['ref'] = data['ref'] or ''
|
||||
vals['name'] = "%s: %s " % (product_obj.browse(cr, uid, data['product_id'], context=context).name, data['name'].decode('utf8'))
|
||||
address_u = res_obj.browse(cr, uid, uid, context=context).address_id
|
||||
if address_u:
|
||||
partner_id = address_u.partner_id and address_u.partner_id.id or None
|
||||
args['partner_id'] = partner_id
|
||||
statement_line_id = statement_line_obj.create(cr, uid, args)
|
||||
vals['partner_id'] = address_u.partner_id and address_u.partner_id.id or None
|
||||
statement_line_id = statement_line_obj.create(cr, uid, vals, context=context)
|
||||
return {}
|
||||
|
||||
pos_box_out()
|
||||
|
|
Loading…
Reference in New Issue