[IMP] point_of_sale: convert pos_payment wizard in osv_memory

bzr revid: sbh@tinyerp.com-20100326113253-su4gskwkkg8gq66c
This commit is contained in:
sbh (Open ERP) 2010-03-26 17:02:53 +05:30
parent 67480b3904
commit b65b70bb07
7 changed files with 255 additions and 237 deletions

View File

@ -61,6 +61,7 @@ Main features :
'wizard/pos_receipt_view.xml',
'wizard/pos_payment_report_user.xml',
'wizard/pos_payment_report.xml',
'wizard/pos_payment.xml',
'pos_report.xml',
'pos_wizard.xml',
'pos_view.xml',

View File

@ -68,7 +68,7 @@
<button name="%(pos_add_product)d" string="_Add product" type="action" states="draft"/>
-->
<button name="%(pos_payment)d" string="Ma_ke Payment" icon="gtk-ok" type="action" states="draft,advance"/>
<button name="%(action_pos_payment)d" string="Ma_ke Payment" icon="gtk-ok" type="action" states="draft,advance" context="{'record_id':'active_id'}" />
<button name="%(action_report_pos_receipt)d" string="_Reprint" icon="gtk-print" type="action" states="paid,done,invoiced"/>

View File

@ -13,8 +13,8 @@
<!-- <wizard string="Box Entries" model="account.bank.statement"
name="pos.entry" id="pos_entry" menu="False"/>-->
<wizard string="Payment" model="pos.order"
name="pos.payment" id="pos_payment" menu="False"/>
<!-- <wizard string="Payment" model="pos.order"
name="pos.payment" id="pos_payment" menu="False"/>-->
<!--<wizard string="Create Invoices" model="pos.order"
name="pos.create_invoice" id="pos_invoice" multi="True"/>-->

View File

@ -20,7 +20,7 @@
#
##############################################################################
import wizard_pos_payment
#import wizard_pos_payment
import wizard_default_journal
import wizard_scan_product
@ -49,6 +49,7 @@ import pos_receipt
import pos_payment_report_user
import pos_payment_report_date
import pos_payment_report
import pos_payment
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,204 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import netsvc
from osv import osv,fields
from tools.translate import _
import pos_box_entries
import time
from decimal import Decimal
from tools.translate import _
import pos_receipt
class pos_make_payment(osv.osv_memory):
_name = 'pos.make.payment'
_description = 'Point of Sale Payment'
def default_get(self, cr, uid, fields, context):
"""
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
res = super(pos_make_payment, self).default_get(cr, uid, fields, context=context)
record_id = context and context.get('active_id',False)
j_obj = self.pool.get('account.journal')
c = self.pool.get('res.users').browse(cr,uid,uid).company_id.id
journal = j_obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', c)])
if journal:
journal = journal[0]
else:
journal = None
wf_service = netsvc.LocalService("workflow")
order = self.pool.get('pos.order').browse(cr, uid, record_id, context)
#get amount to pay
amount = order.amount_total - order.amount_paid
if amount<=0.0:
context.update({'flag':True})
self.pool.get('pos.order').action_paid(cr,uid,[record_id],context)
elif order.amount_paid > 0.0:
self.pool.get('pos.order').write(cr, uid, [record_id],{'state':'advance'})
invoice_wanted_checked = False
current_date = time.strftime('%Y-%m-%d')
if 'journal' in fields:
res.update({'journal':journal})
if 'amount' in fields:
res.update({'amount':amount})
if 'invoice_wanted' in fields:
res.update({'invoice_wanted':invoice_wanted_checked})
if 'payment_date' in fields:
res.update({'payment_date':current_date})
if 'payment_name' in fields:
res.update({'payment_name':'Payment'})
return res
def view_init(self, cr, uid, fields_list, context=None):
res = super(pos_make_payment, self).view_init(cr, uid, fields_list, context=context)
record_id = context and context.get('active_id', False) or False
order = self.pool.get('pos.order').browse(cr, uid, record_id)
if not order.lines:
raise osv.except_osv('Error!','No Order Lines ')
True
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
Changes the view dynamically
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return: New arch of view.
"""
record_id = context and context.get('record_id', False) or False
res = super(pos_make_payment, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
print "::::::::record_idrecord_id:::::::",context
if record_id:
order = self.pool.get('pos.order').browse(cr, uid, record_id)
amount = order.amount_total - order.amount_paid
if amount==0.0:
res['arch'] = """ <form string="Make Payment" colspan="4">
<group col="2" colspan="2">
<label string="Do you want to print the Receipt?" colspan="4"/>
<separator colspan="4"/>
<button icon="gtk-cancel" special="cancel" string="No" readonly="0"/>
<button name="print_report" string="Print Receipt" type="object" icon="gtk-ok"/>
</group>
</form>
"""
return res
def check(self, cr, uid, ids, context=None):
"""Check the order:
if the order is not paid: continue payment,
if the order is paid print invoice (if wanted) or ticket.
"""
record_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, record_id, context)
amount = order.amount_total - order.amount_paid
data = self.read(cr, uid, ids)[0]
print "::::::::",data
# 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, [record_id], {'invoice_wanted': invoice_wanted})
order_obj.add_payment(cr, uid, record_id, data, context=context)
if amount<=0.0:
context.update({'flag':True})
order_obj.action_paid(cr,uid,[record_id],context)
if order_obj.test_paid(cr, uid, [record_id]):
if order.partner_id and order.invoice_wanted:
return self.create_invoice(cr,uid,ids,context)
else:
return self.print_report(cr, uid, ids, context)
return {}
def create_invoice(self, cr, uid, ids, context):
wf_service = netsvc.LocalService("workflow")
record_ids = context and context.get('active_ids',False)
for i in record_ids:
wf_service.trg_validate(uid, 'pos.order', i, 'invoice', cr)
datas = {'ids' : context.get('active_ids', [])}
return {
'type' : 'ir.actions.report.xml',
'report_name':'pos.invoice',
'datas' : datas,
}
def print_report(self, cr, uid, ids, context=None):
if not context:
context={}
"""
@summary: To get the date and print the report
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return : retrun report
"""
datas = {'ids' : context.get('active_ids',[])}
res = {}
datas['form'] = res
return {
'type' : 'ir.actions.report.xml',
'report_name':'pos.receipt',
'datas' : datas,
}
def trigger_wkf(self, cr, uid, data, context):
record_id = context and context.get('active_id',False)
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'pos.order', record_id, 'payment', cr)
return {}
_columns = {
'journal':fields.selection(pos_box_entries.get_journal, "Journal",required=True),
'product_id': fields.many2one('product.product', "Acompte"),
'amount':fields.float('Amount', digits=(16,2) ,required= True),
'payment_name': fields.char('Payment name', size=32, required=True),
'payment_date': fields.date('Payment date', required=True),
'is_acc': fields.boolean('Accompte'),
'invoice_wanted': fields.boolean('Invoice'),
'num_sale':fields.char('Num.File', size=32),
}
pos_make_payment()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
"""
<!-- Select an Open Sale Order -->
<record id="view_pos_payment" model="ir.ui.view">
<field name="name">Add payment :</field>
<field name="model">pos.make.payment</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Add payment :">
<group colspan="4" >
<field name="amount" />
<field name="journal"/>
<field name="payment_date" />
<field name="payment_name" />
<field name="invoice_wanted" />
<field name="num_sale" />
<field name="is_acc" />
<group attrs="{'readonly':[('is_acc','=',False)]}" colspan="4" col="2">
<field name="product_id" attrs="{'required':[('is_acc', '=', True)]}" domain="[('type','=','service')]"/>
</group>
<newline/>
<separator orientation="vertical"/>
<button icon='gtk-cancel' special="cancel" string="Cancel" />
<button name="trigger_wkf" string="Finish" colspan="1" type="object" icon="gtk-ok"/>
<button name="check" string="Make Payment" colspan="1" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_pos_payment" model="ir.actions.act_window">
<field name="name">Add payment</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">pos.make.payment</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -1,233 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import pooler
import netsvc
import wizard
import time
from decimal import Decimal
from tools.translate import _
def _get_journal(self, cr, uid, context):
pool = pooler.get_pool(cr.dbname)
obj = pool.get('account.journal')
c=pool.get('res.users').browse(cr,uid,uid).company_id.id
ids = obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', c)])
res = obj.read(cr, uid, ids, ['id', 'name'], context)
res = [(r['id'], r['name']) for r in res]
return res
payment_form = """<?xml version="1.0"?>
<form string="Add payment :">
<group colspan="4" label="Payment">
<field name="amount" />
<field name="journal"/>
<field name="payment_date" />
<field name="payment_name" />
<field name="invoice_wanted" />
<field name="num_sale" />
<field name="is_acc" />
<group attrs="{'readonly':[('is_acc','=',False)]}" colspan="4" cols="2">
<field name="product_id" attrs="{'required':[('is_acc', '=', True)]}" domain="[('type','=','service')]"/>
</group>
</group>
</form>
"""
payment_fields = {
'amount': {'string': 'Amount', 'type': 'float', 'required': True},
'is_acc': {'string': 'Accompte', 'type': 'boolean'},
'invoice_wanted': {'string': 'Invoice', 'type': 'boolean'},
'journal': {'string': 'Journal',
'type': 'selection',
'selection': _get_journal,
'required': True,
},
'payment_date': {'string': 'Payment date', 'type': 'date', 'required': True},
'payment_name': {'string': 'Payment name', 'type': 'char', 'size': '32', 'required':True, 'default':'Payment'},
'num_sale': {'string': 'Num.File', 'type': 'char', 'size': '32'},
'product_id': {'string':'Acompte','type': 'many2one', 'relation': 'product.product'},
}
def _pre_init(self, cr, uid, data, context):
def _get_journal(pool, order):
j_obj = pool.get('account.journal')
c = pool.get('res.users').browse(cr,uid,uid).company_id.id
journal = j_obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', c)])
if journal:
journal = journal[0]
else:
journal = None
return journal
wf_service = netsvc.LocalService("workflow")
# wf_service.trg_validate(uid, 'pos.order', data['id'], 'start_payment', cr)
pool = pooler.get_pool(cr.dbname)
order = pool.get('pos.order').browse(cr, uid, data['id'], context)
#get amount to pay
#amount = Decimal(str(order.amount_total)) - Decimal(str(order.amount_paid))
amount = order.amount_total - order.amount_paid
if amount<=0:
context.update({'flag':True})
pool.get('pos.order').action_paid(cr,uid,data['ids'],context)
elif order.amount_paid > 0:
pool.get('pos.order').write(cr, uid, data['id'],{'state':'advance'})
# get journal:
journal = _get_journal(pool, order)
# check if an invoice is wanted:
#invoice_wanted_checked = not not order.partner_id # not not -> boolean
invoice_wanted_checked = False
# select the current date
current_date = time.strftime('%Y-%m-%d')
return {'journal': journal, 'amount': amount, 'invoice_wanted': invoice_wanted_checked, 'payment_date': current_date}
def _add_pay(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
order_obj = pool.get('pos.order')
jrnl_obj = pool.get('account.journal')
result = data['form']
invoice_wanted = data['form']['invoice_wanted']
jrnl_used=False
if data['form'] and data['form'].get('journal',False):
jrnl_used=jrnl_obj.browse(cr,uid,data['form']['journal'])
# add 'invoice_wanted' in 'pos.order'
order_obj.write(cr, uid, [data['id']], {'invoice_wanted': invoice_wanted})
order_obj.add_payment(cr, uid, data['id'], result, context=context)
return {}
def _check(self, cr, uid, data, context):
"""Check the order:
if the order is not paid: continue payment,
if the order is paid print invoice (if wanted) or ticket.
"""
pool = pooler.get_pool(cr.dbname)
order_obj = pool.get('pos.order')
order = order_obj.browse(cr, uid, data['id'], context)
amount = order.amount_total - order.amount_paid
if amount<=0:
context.update({'flag':True})
pool.get('pos.order').action_paid(cr,uid,data['ids'],context)
action = 'ask_pay'
if order_obj.test_paid(cr, uid, [data['id']]):
if order.partner_id:
if order.invoice_wanted:
action = 'invoice'
else:
action = 'paid'
elif order.date_payment:
action = 'receipt'
else:
action = 'paid'
return action
def create_invoice(self, cr, uid, data, context):
wf_service = netsvc.LocalService("workflow")
for i in data['ids']:
wf_service.trg_validate(uid, 'pos.order', i, 'invoice', cr)
return {}
def _trigger_wkf(self, cr, uid, data, context):
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'pos.order', data['id'], 'payment', cr)
return {}
class pos_payment(wizard.interface):
states = {
'init': {
'actions': [],
'result': {
'type': 'choice',
'next_state': _check,
}
},
'ask_pay': {
'actions': [_pre_init],
'result': {
'type': 'form',
'arch': payment_form,
'fields': payment_fields,
'state': (('end', 'Cancel'), ('finish', 'Finish'), ('add_pay', 'Ma_ke payment', 'gtk-ok', True))
}
},
'add_pay': {
'actions': [_add_pay],
'result': {
'type': 'state',
'state': "init",
}
},
'invoice': {
'actions': [create_invoice],
'result': {
'type': 'print',
'report': 'pos.invoice',
'state': 'finish'
}
},
'receipt': {
'actions': [],
'result': {
'type': 'print',
'report': 'pos.receipt',
'state': 'finish'
}
},
'paid': {
'actions': [],
'result': {
'type': 'print',
'report': 'pos.receipt',
'state': 'finish'
}
},
'finish': {
'actions': [_trigger_wkf],
'result': {
'type': 'state',
'state': 'end'
}
},
}
pos_payment('pos.payment')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: