[ADD] auction: Added 'Lots Invoice' wizard converting to osv_memory wizard to print report.
bzr revid: uco@tinyerp.co.in-20100319122949-y825szqzrjjfen6v
This commit is contained in:
parent
3641b2094e
commit
92b994847d
|
@ -0,0 +1,124 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
import netsvc
|
||||
from tools.translate import _
|
||||
|
||||
class auction_lots_invoice(osv.osv_memory):
|
||||
_name = 'auction.lots.invoice'
|
||||
_description = "Auction Lots Invoice"
|
||||
|
||||
_columns = {
|
||||
'amount': fields.float('Invoiced Amount', required=True, readonly=True),
|
||||
'amount_topay': fields.float('Amount to pay', required=True, readonly=True),
|
||||
'amount_paid': fields.float('Amount paid', readonly=True),
|
||||
'objects': fields.integer('# of objects', required=True, readonly=True),
|
||||
'ach_uid': fields.many2one('res.partner','Buyer Name', required=True ),
|
||||
'number': fields.integer('Invoice Number'),
|
||||
# 'tax_applied':{'string':'Tax Applied', 'type':'float', 'readonly':True},
|
||||
}
|
||||
|
||||
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(auction_lots_invoice, self).default_get(cr, uid, fields, context=context)
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
lots = service.execute(cr.dbname, uid, 'auction.lots', 'read', context.get('active_ids', []))
|
||||
auction = service.execute(cr.dbname,uid, 'auction.dates', 'read', [lots[0]['auction_id'][0]])[0]
|
||||
|
||||
price = 0.0
|
||||
price_topay = 0.0
|
||||
price_paid = 0.0
|
||||
#tax=data['form']['tax_applied']
|
||||
# uid = False
|
||||
for lot in lots:
|
||||
price_lot = lot['obj_price'] or 0.0
|
||||
|
||||
costs = service.execute(cr.dbname, uid, 'auction.lots', 'compute_buyer_costs', [lot['id']])
|
||||
price_lot += costs['amount']
|
||||
# for cost in costs:
|
||||
# price_lot += cost['amount']
|
||||
|
||||
price += price_lot
|
||||
|
||||
if lot['ach_uid']:
|
||||
if uid and (lot['ach_uid'][0]<>uid):
|
||||
raise osv.except_osv(_('UserError'), _('Two different buyers for the same invoice !\nPlease correct this problem before invoicing'))
|
||||
uid = lot['ach_uid'][0]
|
||||
elif lot['ach_login']:
|
||||
refs = service.execute(uid, 'res.partner', 'search', [('ref','=',lot['ach_login'])])
|
||||
if len(refs):
|
||||
uid = refs[-1]
|
||||
if 'ach_pay_id' in lot and lot['ach_pay_id']:
|
||||
price_paid += price_lot
|
||||
#*tax
|
||||
else:
|
||||
price_topay += price_lot
|
||||
#*tax
|
||||
|
||||
#TODO: recuperer id next invoice (de la sequence)???
|
||||
invoice_number = False
|
||||
for lot in self.pool.get('auction.lots').browse(cr, uid, context.get('active_ids', [])):
|
||||
if 'objects' in fields:
|
||||
res.update({'objects':len(context.get('active_ids', []))})
|
||||
if 'amount' in fields:
|
||||
res.update({'amount': price})
|
||||
if 'ach_uid' in fields:
|
||||
res.update({'ach_uid': uid})
|
||||
if 'amount_topay' in fields:
|
||||
res.update({'amount_topay':price_topay})
|
||||
if 'amount_paid' in fields:
|
||||
res.update({'amount_paid':price_paid})
|
||||
if 'number' in fields:
|
||||
res.update({'number':invoice_number})
|
||||
return res
|
||||
|
||||
def print_report(self, cr, uid, ids, context={}):
|
||||
"""
|
||||
Create an invoice report.
|
||||
@param cr: the current row, from the database cursor.
|
||||
@param uid: the current user’s ID for security checks.
|
||||
@param ids: List of Auction lots make invoice buyer’s IDs
|
||||
@return: dictionary of account invoice form.
|
||||
"""
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
datas = {'ids' : context.get('active_ids',[])}
|
||||
res = self.read(cr, uid, ids, ['number','ach_uid'])
|
||||
res = res and res[0] or {}
|
||||
datas['form'] = res
|
||||
# service.execute(cr.dbname, uid, 'auction.lots', 'lots_invoice_and_cancel_old_invoice', datas['ids'], datas['form']['number'], datas['form']['ach_uid'], 'invoice_open')
|
||||
return {
|
||||
'type' : 'ir.actions.report.xml',
|
||||
'report_name':'auction.invoice',
|
||||
'datas' : datas,
|
||||
}
|
||||
|
||||
auction_lots_invoice()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Auction Lots Invoice Report -->
|
||||
|
||||
<record id="view_auction_lots_invoice_wizard" model="ir.ui.view">
|
||||
<field name="name">auction.lots.invoice.wizard</field>
|
||||
<field name="model">auction.lots.invoice</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Paid ?">
|
||||
<field name="amount"/>
|
||||
<field name="objects"/>
|
||||
<field name="amount_topay"/>
|
||||
<field name="amount_paid"/>
|
||||
<newline/>
|
||||
<field name="ach_uid"/>
|
||||
<field name="number"/>
|
||||
<label string="Let this invoice's number"/>
|
||||
<group col="2" colspan="4">
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="Cancel" />
|
||||
<button name="print_report" string="Ok"
|
||||
colspan="1" type="object" icon="gtk-ok" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window name="Auction Lots Invoice"
|
||||
res_model="auction.lots.invoice"
|
||||
src_model="auction.dates"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
id="action_auction_lots_invoice_wizard"/>
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,106 +0,0 @@
|
|||
# -*- 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 wizard
|
||||
import netsvc
|
||||
|
||||
invoice_form = '''<?xml version="1.0"?>
|
||||
<form title="Paid ?">
|
||||
<field name="amount"/>
|
||||
<field name="objects"/>
|
||||
<field name="amount_topay"/>
|
||||
<field name="amount_paid"/>
|
||||
<!--field name= "tax_applied"/>-->
|
||||
<newline/>
|
||||
<field name="ach_uid" colspan="3"/>
|
||||
<field name="number" colspan="3"/>
|
||||
<field label="Let this invoice's number "/>
|
||||
</form>'''
|
||||
|
||||
invoice_fields = {
|
||||
'amount': {'string':'Invoiced Amount', 'type':'float', 'required':True, 'readonly':True},
|
||||
'amount_topay': {'string':'Amount to pay', 'type':'float', 'required':True, 'readonly':True},
|
||||
'amount_paid': {'string':'Amount paid', 'type':'float', 'readonly':True},
|
||||
'objects': {'string':'# of objects', 'type':'integer', 'required':True, 'readonly':True},
|
||||
'ach_uid': {'string':'Buyer Name', 'type':'many2one', 'required':True, 'relation':'res.partner'},
|
||||
'number': {'string':'Invoice Number', 'type':'integer'},
|
||||
#'tax_applied':{'string':'Tax Applied', 'type':'float', 'readonly':True},
|
||||
}
|
||||
|
||||
def _get_value(self,cr,uid, datas,context={}):
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
lots = service.execute(cr,uid, 'auction.lots', 'read', datas['ids'])
|
||||
auction = service.execute(cr,uid, 'auction.dates', 'read', [lots[0]['auction_id'][0]])[0]
|
||||
|
||||
price = 0.0
|
||||
price_topay = 0.0
|
||||
price_paid = 0.0
|
||||
#tax=data['form']['tax_applied']
|
||||
uid = False
|
||||
for lot in lots:
|
||||
price_lot = lot['obj_price'] or 0.0
|
||||
|
||||
costs = service.execute(uid, 'auction.lots', 'compute_buyer_costs', [lot['id']])
|
||||
for cost in costs:
|
||||
price_lot += cost['amount']
|
||||
|
||||
price += price_lot
|
||||
|
||||
if lot['ach_uid']:
|
||||
if uid and (lot['ach_uid'][0]<>uid):
|
||||
raise wizard.except_wizard('UserError', ('Two different buyers for the same invoice !\nPlease correct this problem before invoicing', 'init'))
|
||||
uid = lot['ach_uid'][0]
|
||||
elif lot['ach_login']:
|
||||
refs = service.execute(uid, 'res.partner', 'search', [('ref','=',lot['ach_login'])])
|
||||
if len(refs):
|
||||
uid = refs[-1]
|
||||
if lot['ach_pay_id']:
|
||||
price_paid += price_lot
|
||||
#*tax
|
||||
else:
|
||||
price_topay += price_lot
|
||||
#*tax
|
||||
|
||||
#TODO: recuperer id next invoice (de la sequence)???
|
||||
invoice_number = False
|
||||
return {'objects':len(datas['ids']), 'amount':price, 'ach_uid':uid, 'amount_topay':price_topay, 'amount_paid':price_paid, 'number':invoice_number}
|
||||
|
||||
def _invoice(self, uid, datas):
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
service.execute(uid, 'auction.lots', 'lots_invoice_and_cancel_old_invoice', datas['ids'], datas['form']['number'], datas['form']['ach_uid'], 'invoice_open')
|
||||
return {}
|
||||
|
||||
class wiz_auc_lots_invoice(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_get_value],
|
||||
'result': {'type': 'form', 'arch':invoice_form, 'fields': invoice_fields, 'state':[('invoice','Create Invoice'), ('end','Cancel')]}
|
||||
},
|
||||
'invoice': {
|
||||
'actions': [_invoice],
|
||||
'result': {'type': 'print', 'report':'auction.invoice', 'state':'end'}
|
||||
}
|
||||
}
|
||||
wiz_auc_lots_invoice('auction.lots.invoice');
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue