[ADD] hr_timesheet_invoice: Create invoice for analytic lines=> osv memory
bzr revid: mra@tinyerp.com-20100422103440-960ki0xp1lwygzb1
This commit is contained in:
parent
87a76d054e
commit
33bd32903c
|
@ -41,6 +41,7 @@ reports, eso.""",
|
|||
'report/hr_timesheet_invoice_report_view.xml',
|
||||
'wizard/hr_timesheet_invoice_analytic_cost_ledger_view.xml',
|
||||
'wizard/hr_timesheet_analytic_profit_view.xml',
|
||||
'wizard/hr_timesheet_invoice_create_view.xml',
|
||||
],
|
||||
'demo_xml': ['hr_timesheet_invoice_demo.xml'],
|
||||
'installable': True,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<wizard id="hr_timesheet_invoice_create" model="account.analytic.line" name="hr.timesheet.invoice.create" string="Invoice analytic lines"/>
|
||||
<!-- <wizard id="hr_timesheet_invoice_create" model="account.analytic.line" name="hr.timesheet.invoice.create" string="Invoice analytic lines"/>-->
|
||||
<wizard id="hr_timesheet_final_invoice_create" model="account.analytic.account" name="hr.timesheet.final.invoice.create" string="Final Invoice"/>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -19,52 +19,69 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import pooler
|
||||
import time
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
#
|
||||
# Create an invoice based on selected timesheet lines
|
||||
## Create an invoice based on selected timesheet lines
|
||||
#
|
||||
|
||||
#
|
||||
# TODO: check unit of measure !!!
|
||||
#
|
||||
class invoice_create(wizard.interface):
|
||||
def _get_accounts(self, cr, uid, data, context):
|
||||
if not len(data['ids']):
|
||||
class hr_timesheet_invoice_create(osv.osv_memory):
|
||||
|
||||
_name = 'hr.timesheet.invoice.create'
|
||||
_description = 'Create invoice from timesheet'
|
||||
_columns = {
|
||||
'accounts': fields.many2many('account.analytic.account', 'invoice_id', 'account_id', 'Analytic Accounts', required=True),
|
||||
'date': fields.boolean('Date', help='The real date of each work will be displayed on the invoice'),
|
||||
'time': fields.boolean('Time spent', help='The time of each work done will be displayed on the invoice'),
|
||||
'name': fields.boolean('Name of entry', help='The detail of each work done will be displayed on the invoice'),
|
||||
'price': fields.boolean('Cost', help='The cost of each work done will be displayed on the invoice. You probably don\'t want to check this'),
|
||||
'product': fields.many2one('product.product', 'Product', help='Complete this field only if you want to force to use a specific product. Keep empty to use the real product that comes from the cost.'),
|
||||
}
|
||||
|
||||
def _get_accounts(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if not len(context['active_ids']):
|
||||
return {}
|
||||
#Checking whether the analytic line is invoiced or not
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
analytic_line_obj = pool.get('account.analytic.line').browse(cr, uid, data['ids'], context)
|
||||
analytic_line_obj = self.pool.get('account.analytic.line').browse(cr, uid, context['active_ids'], context)
|
||||
for obj_acc in analytic_line_obj:
|
||||
if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel':
|
||||
raise wizard.except_wizard(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))
|
||||
|
||||
cr.execute("SELECT distinct(account_id) from account_analytic_line where id =ANY(%s)",(data['ids'],))
|
||||
account_ids = cr.fetchall()
|
||||
return {'accounts': [x[0] for x in account_ids]}
|
||||
raise osv.except_osv(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))
|
||||
|
||||
cr.execute("SELECT distinct(account_id) from account_analytic_line where id =ANY(%s)",(context['active_ids'],))
|
||||
account_ids = cr.fetchall()
|
||||
return [x[0] for x in account_ids]
|
||||
|
||||
_defaults = {
|
||||
'accounts': _get_accounts
|
||||
}
|
||||
|
||||
def do_create(self, cr, uid, ids, context=None):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
analytic_account_obj = self.pool.get('account.analytic.account')
|
||||
res_partner_obj = self.pool.get('res.partner')
|
||||
account_payment_term_obj = self.pool.get('account.payment.term')
|
||||
invoices = []
|
||||
|
||||
def _do_create(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod_obj = pool.get('ir.model.data')
|
||||
result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter')
|
||||
res = mod_obj.read(cr, uid, result, ['res_id'])
|
||||
analytic_account_obj = pool.get('account.analytic.account')
|
||||
res_partner_obj = pool.get('res.partner')
|
||||
account_payment_term_obj = pool.get('account.payment.term')
|
||||
|
||||
account_ids = data['form']['accounts'][0][2]
|
||||
invoices = []
|
||||
data = self.read(cr, uid, ids, [], context)[0]
|
||||
account_ids = data['accounts']
|
||||
for account in analytic_account_obj.browse(cr, uid, account_ids, context):
|
||||
partner = account.partner_id
|
||||
if (not partner) or not (account.pricelist_id):
|
||||
raise wizard.except_wizard(_('Analytic Account incomplete'),
|
||||
raise osv.except_osv(_('Analytic Account incomplete'),
|
||||
_('Please fill in the Associate Partner and Sale Pricelist fields in the Analytic Account:\n%s') % (account.name,))
|
||||
|
||||
if not partner.address:
|
||||
raise wizard.except_wizard(_('Partner incomplete'),
|
||||
raise osv.except_osv(_('Partner incomplete'),
|
||||
_('Please fill in the Address field in the Partner: %s.') % (partner.name,))
|
||||
|
||||
date_due = False
|
||||
|
@ -90,7 +107,7 @@ class invoice_create(wizard.interface):
|
|||
'date_due': date_due,
|
||||
'fiscal_position': account.partner_id.property_account_position.id
|
||||
}
|
||||
last_invoice = pool.get('account.invoice').create(cr, uid, curr_invoice)
|
||||
last_invoice = self.pool.get('account.invoice').create(cr, uid, curr_invoice)
|
||||
invoices.append(last_invoice)
|
||||
|
||||
context2=context.copy()
|
||||
|
@ -99,26 +116,26 @@ class invoice_create(wizard.interface):
|
|||
"FROM account_analytic_line as line " \
|
||||
"WHERE account_id = %s " \
|
||||
"AND id =ANY(%s) AND to_invoice IS NOT NULL " \
|
||||
"GROUP BY product_id,to_invoice", (account.id,data['ids'],))
|
||||
"GROUP BY product_id,to_invoice", (account.id,context['active_ids'],))
|
||||
|
||||
for product_id,factor_id,qty in cr.fetchall():
|
||||
product = pool.get('product.product').browse(cr, uid, product_id, context2)
|
||||
if not product:
|
||||
raise wizard.except_wizard(_('Error'), _('At least one line has no product !'))
|
||||
raise osv.except_osv(_('Error'), _('At least one line has no product !'))
|
||||
factor_name = ''
|
||||
factor = pool.get('hr_timesheet_invoice.factor').browse(cr, uid, factor_id, context2)
|
||||
|
||||
if not data['form']['product']:
|
||||
if not data['product']:
|
||||
if factor.customer_name:
|
||||
factor_name = product.name+' - '+factor.customer_name
|
||||
else:
|
||||
factor_name = product.name
|
||||
else:
|
||||
factor_name = pool.get('product.product').name_get(cr, uid, [data['form']['product']], context=context)[0][1]
|
||||
factor_name = pool.get('product.product').name_get(cr, uid, [data['product']], context=context)[0][1]
|
||||
|
||||
if account.pricelist_id:
|
||||
pl = account.pricelist_id.id
|
||||
price = pool.get('product.pricelist').price_get(cr,uid,[pl], data['form']['product'] or product_id, qty or 1.0, account.partner_id.id)[pl]
|
||||
price = pool.get('product.pricelist').price_get(cr,uid,[pl], data['product'] or product_id, qty or 1.0, account.partner_id.id)[pl]
|
||||
else:
|
||||
price = 0.0
|
||||
|
||||
|
@ -132,7 +149,7 @@ class invoice_create(wizard.interface):
|
|||
'invoice_line_tax_id': [(6,0,tax )],
|
||||
'invoice_id': last_invoice,
|
||||
'name': factor_name,
|
||||
'product_id': data['form']['product'] or product_id,
|
||||
'product_id': data['product'] or product_id,
|
||||
'invoice_line_tax_id': [(6,0,tax)],
|
||||
'uos_id': product.uom_id.id,
|
||||
'account_id': account_id,
|
||||
|
@ -149,27 +166,27 @@ class invoice_create(wizard.interface):
|
|||
for line in line_ids:
|
||||
# set invoice_line_note
|
||||
details = []
|
||||
if data['form']['date']:
|
||||
if data['date']:
|
||||
details.append(line['date'])
|
||||
if data['form']['time']:
|
||||
if data['time']:
|
||||
if line['product_uom_id']:
|
||||
details.append("%s %s" % (line['unit_amount'], pool.get('product.uom').browse(cr, uid, [line['product_uom_id']])[0].name))
|
||||
else:
|
||||
details.append("%s" % (line['unit_amount'], ))
|
||||
if data['form']['name']:
|
||||
if data['name']:
|
||||
details.append(line['name'])
|
||||
#if data['form']['price']:
|
||||
#if data['price']:
|
||||
# details.append(abs(line['amount']))
|
||||
note.append(u' - '.join(map(lambda x: unicode(x) or '',details)))
|
||||
|
||||
curr_line['note'] = "\n".join(map(lambda x: unicode(x) or '',note))
|
||||
pool.get('account.invoice.line').create(cr, uid, curr_line)
|
||||
cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id =ANY(%s)" ,(last_invoice,account.id,data['ids']))
|
||||
cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id =ANY(%s)" ,(last_invoice, account.id,data['ids']))
|
||||
|
||||
pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)
|
||||
self.pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)
|
||||
|
||||
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
|
||||
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
act_obj = self.pool.get('ir.actions.act_window')
|
||||
|
||||
mod_id = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')])[0]
|
||||
res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id']
|
||||
|
@ -190,45 +207,8 @@ class invoice_create(wizard.interface):
|
|||
# 'search_view_id': res['res_id']
|
||||
# }
|
||||
|
||||
_create_form = """<?xml version="1.0"?>
|
||||
<form string="Invoice on analytic entries">
|
||||
<notebook>
|
||||
<page string="Billing Data">
|
||||
<separator string="Do you want to show details of work in invoice ?" colspan="4"/>
|
||||
<field name="date"/>
|
||||
<field name="time"/>
|
||||
<field name="name"/>
|
||||
<field name="price"/>
|
||||
<separator string="Force to use a specific product" colspan="4"/>
|
||||
<field name="product"/>
|
||||
</page>
|
||||
<page string="Filter on Accounts" groups="base.group_extended">
|
||||
<separator string="Choose accounts you want to invoice" colspan="4"/>
|
||||
<field name="accounts" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>"""
|
||||
|
||||
_create_fields = {
|
||||
'accounts': {'string':'Analytic Accounts', 'type':'many2many', 'required':'true', 'relation':'account.analytic.account'},
|
||||
'date': {'string':'Date', 'type':'boolean', 'help':'The real date of each work will be displayed on the invoice'},
|
||||
'time': {'string':'Time spent', 'type':'boolean', 'help':'The time of each work done will be displayed on the invoice'},
|
||||
'name': {'string':'Name of entry', 'type':'boolean', 'help':'The detail of each work done will be displayed on the invoice'},
|
||||
'price': {'string':'Cost', 'type':'boolean', 'help':'The cost of each work done will be displayed on the invoice. You probably don\'t want to check this.'},
|
||||
'product': {'string':'Product', 'type':'many2one', 'relation': 'product.product', 'help':"Complete this field only if you want to force to use a specific product. Keep empty to use the real product that comes from the cost."},
|
||||
}
|
||||
|
||||
states = {
|
||||
'init' : {
|
||||
'actions' : [_get_accounts],
|
||||
'result' : {'type':'form', 'arch':_create_form, 'fields':_create_fields, 'state': [('end','Cancel', 'gtk-cancel'),('create','Create Invoices', 'gtk-ok')]},
|
||||
},
|
||||
'create' : {
|
||||
'actions' : [],
|
||||
'result' : {'type':'action', 'action':_do_create, 'state':'end'},
|
||||
},
|
||||
}
|
||||
invoice_create('hr.timesheet.invoice.create')
|
||||
hr_timesheet_invoice_create()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_hr_timesheet_invoice_create" model="ir.ui.view">
|
||||
<field name="name">hr.timesheet.invoice.create.form</field>
|
||||
<field name="model">hr.timesheet.invoice.create</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Invoice analytic lines">
|
||||
<group col="4" colspan="6">
|
||||
<notebook>
|
||||
<page string="Billing Data">
|
||||
<separator string="Do you want to show details of work in invoice ?" colspan="4"/>
|
||||
<field name="date"/>
|
||||
<field name="time"/>
|
||||
<field name="name"/>
|
||||
<field name="price"/>
|
||||
<separator string="Force to use a specific product" colspan="4"/>
|
||||
<field name="product"/>
|
||||
</page>
|
||||
<page string="Filter on Accounts" groups="base.group_extended">
|
||||
<separator string="Choose accounts you want to invoice" colspan="4"/>
|
||||
<field name="accounts" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group col="2" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||
<button name="do_create" string="Create Invoices" colspan="1" type="object" icon="gtk-execute"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hr_timesheet_invoice_create" model="ir.actions.act_window">
|
||||
<field name="name">Invoice analytic lines</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">hr.timesheet.invoice.create</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="hr_timesheet_invoice_create_values">
|
||||
<field name="model_id" ref="model_account_analytic_line" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Invoice analytic lines</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_hr_timesheet_invoice_create'))" />
|
||||
<field name="key">action</field>
|
||||
<field name="model">account.analytic.line</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue