[MOD/IMP] point_of_sale : Improvement in payment,return and invoice wizards
bzr revid: vir@tinyerp.com-20100811103012-rg0u3s0aieao6qhe
This commit is contained in:
parent
e7dc8c2d55
commit
9e19f017f3
|
@ -34,19 +34,19 @@ class pos_invoice(report_sxw.rml_parse):
|
|||
})
|
||||
|
||||
|
||||
def set_context(self, order, data, ids, report_type=None):
|
||||
super(pos_invoice, self).set_context(order, data, ids, report_type)
|
||||
def set_context(self, objects, data, ids, report_type=None):
|
||||
super(pos_invoice, self).set_context(objects, data, ids, report_type)
|
||||
iids = []
|
||||
nids = []
|
||||
|
||||
for order in objects:
|
||||
order.write({'nb_print': order.nb_print + 1})
|
||||
|
||||
order.write({'nb_print': order.nb_print + 1})
|
||||
|
||||
if order.invoice_id and order.invoice_id not in iids:
|
||||
if not order.invoice_id:
|
||||
raise osv.except_osv(_('Error !'), _('Please create an invoice for this sale.'))
|
||||
iids.append(order.invoice_id)
|
||||
nids.append(order.invoice_id.id)
|
||||
if order.invoice_id and order.invoice_id not in iids:
|
||||
if not order.invoice_id:
|
||||
raise osv.except_osv(_('Error !'), _('Please create an invoice for this sale.'))
|
||||
iids.append(order.invoice_id)
|
||||
nids.append(order.invoice_id.id)
|
||||
data['ids'] = nids
|
||||
self.datas = data
|
||||
self.ids = nids
|
||||
|
|
|
@ -131,105 +131,29 @@ class pos_make_payment(osv.osv_memory):
|
|||
"""
|
||||
active_id = context and context.get('active_id',False)
|
||||
order_obj = self.pool.get('pos.order')
|
||||
jrnl_obj = self.pool.get('account.journal')
|
||||
order = order_obj.browse(cr, uid, active_id, context)
|
||||
order_name = order.name
|
||||
amount = order.amount_total - order.amount_paid
|
||||
data = self.read(cr, uid, ids)[0]
|
||||
|
||||
invoice_wanted = data['invoice_wanted']
|
||||
# Todo need to check ...
|
||||
if amount !=0.0:
|
||||
invoice_wanted = data['invoice_wanted']
|
||||
jrnl_used=False
|
||||
if data.get('journal',False):
|
||||
jrnl_used=jrnl_obj.browse(cr, uid, data['journal'])
|
||||
order_obj.write(cr, uid, [active_id], {'invoice_wanted': invoice_wanted})
|
||||
order_obj.add_payment(cr, uid, active_id, data, context=context)
|
||||
|
||||
res_obj = self.pool.get('res.company')
|
||||
inv_ref = self.pool.get('account.invoice')
|
||||
inv_line_ref = self.pool.get('account.invoice.line')
|
||||
product_obj= self.pool.get('product.product')
|
||||
inv_ids = []
|
||||
for order in self.pool.get('pos.order').browse(cr, uid, ids, context):
|
||||
# curr_c = order.user_salesman_id.company_id
|
||||
make_obj = self.pool.get('pos.make.payment').browse(cr, uid, uid)
|
||||
if invoice_wanted:
|
||||
if order.invoice_id:
|
||||
inv_ids.append(order.invoice_id.id)
|
||||
# continue
|
||||
# if not make_obj.partner_id:
|
||||
# raise osv.except_osv(_('Error'), _('Please provide a partner for the sale.'))
|
||||
acc= make_obj.partner_id.property_account_receivable.id
|
||||
inv = {
|
||||
'name': 'Invoice from POS: '+order_name,
|
||||
'origin': order_name,
|
||||
'account_id':acc,
|
||||
'journal_id':order.sale_journal.id or None,
|
||||
'type': 'out_invoice',
|
||||
'reference': order.name,
|
||||
'partner_id': make_obj.partner_id.id,
|
||||
'comment': order.note or '',
|
||||
}
|
||||
inv.update(inv_ref.onchange_partner_id(cr, uid, [], 'out_invoice', make_obj.partner_id.id)['value'])
|
||||
if not inv.get('account_id', None):
|
||||
inv['account_id'] = acc
|
||||
inv_id = inv_ref.create(cr, uid, inv, context)
|
||||
self.write(cr, uid, [order.id], {'invoice_id': inv_id, 'state': 'invoiced'})
|
||||
inv_ids.append(inv_id)
|
||||
for line in order.lines:
|
||||
inv_line = {
|
||||
'invoice_id': inv_id,
|
||||
'product_id': line.product_id.id,
|
||||
'quantity': line.qty,
|
||||
}
|
||||
inv_name = product_obj.name_get(cr, uid, [line.product_id.id], context=context)[0][1]
|
||||
|
||||
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 = make_obj.partner_id.id, fposition_id=make_obj.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['price_unit'] = amount
|
||||
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)
|
||||
for i in inv_ids:
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'account.invoice', i, 'invoice_open', cr)
|
||||
# return inv_ids
|
||||
# Todo need to check
|
||||
# if amount<=0.0:
|
||||
# if amount <= 0.0:
|
||||
# context.update({'flag':True})
|
||||
# order_obj.action_paid(cr,uid,[active_id],context)
|
||||
# order_obj.action_paid(cr, uid, [active_id], context)
|
||||
# return self.print_report(cr, uid, ids, context)
|
||||
|
||||
# def test_paid(self, cr, uid, ids, context=None):
|
||||
# """ Test all amount is paid for this order
|
||||
# @return: True
|
||||
# """
|
||||
# for order in self.browse(cr, uid, ids, context):
|
||||
# if order.lines and not order.amount_total:
|
||||
# return True
|
||||
# if (not order.lines) or (not order.statement_ids) or \
|
||||
# Decimal(str(order.amount_total))!=Decimal(str(order.amount_paid)):
|
||||
# return False
|
||||
# return True
|
||||
# if order_obj.test_paid(cr, uid, [active_id]):
|
||||
if order_obj.browse(cr, uid, [active_id]):
|
||||
if make_obj.partner_id and make_obj.invoice_wanted:
|
||||
order_obj.write(cr, uid, [active_id],{'state':'paid'})
|
||||
if amount != 0.0:
|
||||
order_obj.write(cr, uid, [active_id], {'invoice_wanted': invoice_wanted, 'partner_id': data['partner_id']})
|
||||
order_obj.add_payment(cr, uid, active_id, data, context=context)
|
||||
|
||||
if order_obj.test_paid(cr, uid, [active_id]):
|
||||
if data['partner_id'] and invoice_wanted:
|
||||
order_obj.action_invoice(cr, uid, [active_id], context)
|
||||
if context.get('return'):
|
||||
order_obj.write(cr, uid, [active_id],{'state':'done'})
|
||||
else:
|
||||
order_obj.write(cr, uid, [active_id],{'state':'paid'})
|
||||
return self.print_report(cr, uid, ids, context)
|
||||
# return self.create_invoice(cr, uid, ids, context)
|
||||
return self.create_invoice(cr, uid, ids, context)
|
||||
else:
|
||||
context.update({'flag': True})
|
||||
order_obj.action_paid(cr, uid, [active_id], context)
|
||||
|
@ -238,26 +162,23 @@ class pos_make_payment(osv.osv_memory):
|
|||
else:
|
||||
order_obj.write(cr, uid, [active_id],{'state':'paid'})
|
||||
return self.print_report(cr, uid, ids, context)
|
||||
|
||||
if order.amount_paid > 0.0:
|
||||
context.update({'flag': True})
|
||||
# Todo need to check
|
||||
order_obj.action_paid(cr, uid, [active_id], context)
|
||||
self.pool.get('pos.order').write(cr, uid, [active_id],{'state':'advance'})
|
||||
order_obj.write(cr, uid, [active_id],{'state': 'advance'})
|
||||
return self.print_report(cr, uid, ids, context)
|
||||
# return {}
|
||||
return inv_ids
|
||||
return {}
|
||||
|
||||
|
||||
def create_invoice(self, cr, uid, ids, context):
|
||||
|
||||
"""
|
||||
Create a invoice
|
||||
"""
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
active_ids = [context and context.get('active_id',False)]
|
||||
for i in active_ids:
|
||||
wf_service.trg_validate(uid, 'pos.order', i, 'invoice', cr)
|
||||
datas = {'ids' : context.get('active_id', [])}
|
||||
datas = {'ids': active_ids}
|
||||
datas['form'] = {}
|
||||
return {
|
||||
'type' : 'ir.actions.report.xml',
|
||||
'report_name':'pos.invoice',
|
||||
|
|
|
@ -32,10 +32,6 @@ class pos_return(osv.osv_memory):
|
|||
_name = 'pos.return'
|
||||
_description = 'Point of sale return'
|
||||
|
||||
_columns = {
|
||||
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
To get default values for the object.
|
||||
|
@ -174,55 +170,53 @@ class pos_return(osv.osv_memory):
|
|||
#Todo :Need to clean the code
|
||||
if active_id:
|
||||
picking_ids = picking_obj.search(cr, uid, [('pos_order', 'in',[active_id]), ('state', '=', 'done')])
|
||||
data=self.read(cr,uid,ids)[0]
|
||||
data = self.read(cr, uid, ids)[0]
|
||||
clone_list = []
|
||||
date_cur=time.strftime('%Y-%m-%d')
|
||||
date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
for order_id in order_obj.browse(cr, uid, [active_id], context=context):
|
||||
prop_ids = property_obj.search(cr, uid,[('name', '=', 'property_stock_customer')])
|
||||
val = property_obj.browse(cr, uid, prop_ids[0]).value_reference
|
||||
cr.execute("select s.id from stock_location s, stock_warehouse w where w.lot_stock_id=s.id and w.id= %d "%(order_id.shop_id.warehouse_id.id))
|
||||
res=cr.fetchone()
|
||||
location_id=res and res[0] or None
|
||||
res = cr.fetchone()
|
||||
location_id = res and res[0] or None
|
||||
stock_dest_id = val.id
|
||||
|
||||
new_picking=picking_obj.copy(cr, uid, order_id.picking_id.id, {'name':'%s (return)' % order_id.name,
|
||||
'move_lines':[], 'state':'draft', 'type':'in',
|
||||
'type':'in',
|
||||
'date':date_cur})
|
||||
new_order=order_obj.copy(cr, uid, order_id.id, {'name': 'Refund %s'%order_id.name,
|
||||
new_picking = picking_obj.copy(cr, uid, order_id.picking_id.id, {'name':'%s (return)' % order_id.name,
|
||||
'move_lines': [],
|
||||
'state':'draft',
|
||||
'type': 'in',
|
||||
'address_id': order_id.partner_id.id,
|
||||
'date': date_cur })
|
||||
new_order = order_obj.copy(cr, uid, order_id.id, {'name': 'Refund %s'%order_id.name,
|
||||
'lines':[],
|
||||
'statement_ids':[],
|
||||
'picking_id':[]})
|
||||
for line in order_id.lines:
|
||||
if line.id :
|
||||
if line.id:
|
||||
try:
|
||||
qty= data['return%s' %line.id]
|
||||
qty = data['return%s' %line.id]
|
||||
except :
|
||||
qty= line.qty
|
||||
new_move=stock_move_obj.create(cr, uid,{
|
||||
qty = line.qty
|
||||
new_move = stock_move_obj.create(cr, uid,{
|
||||
'product_qty': qty ,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, qty ,line.product_id.uom_id.id),
|
||||
'picking_id':new_picking,
|
||||
'product_uom':line.product_id.uom_id.id,
|
||||
'location_id':location_id,
|
||||
'product_id':line.product_id.id,
|
||||
'location_dest_id':stock_dest_id,
|
||||
'name':'%s (return)' %order_id.name,
|
||||
'date':date_cur,
|
||||
'date_planned':date_cur,})
|
||||
line_obj.copy(cr,uid,line.id,{'qty':-qty ,
|
||||
'order_id': new_order,
|
||||
})
|
||||
order_obj.write(cr,uid, active_id, {'state':'done'})
|
||||
order_obj.write(cr,uid, new_order, {'state':'done'})
|
||||
'picking_id': new_picking,
|
||||
'product_uom': line.product_id.uom_id.id,
|
||||
'location_id': location_id,
|
||||
'product_id': line.product_id.id,
|
||||
'location_dest_id': stock_dest_id,
|
||||
'name': '%s (return)' %order_id.name,
|
||||
'date': date_cur,
|
||||
'date_planned': date_cur,})
|
||||
line_obj.copy(cr, uid, line.id, {'qty': -qty, 'order_id': new_order})
|
||||
order_obj.write(cr,uid, [active_id,new_order], {'state': 'done'})
|
||||
wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
|
||||
picking_obj.force_assign(cr, uid, [new_picking], context)
|
||||
act = {
|
||||
'domain': "[('id', 'in', ["+str(new_order)+"])]",
|
||||
'name': 'Refunded Orders',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'pos.order',
|
||||
'auto_refresh':0,
|
||||
'res_id':new_order,
|
||||
|
@ -233,6 +227,7 @@ class pos_return(osv.osv_memory):
|
|||
return act
|
||||
|
||||
pos_return()
|
||||
|
||||
class add_product(osv.osv_memory):
|
||||
_inherit = 'pos.add.product'
|
||||
def select_product(self, cr, uid, ids, context):
|
||||
|
|
Loading…
Reference in New Issue