diff options
Diffstat (limited to 'addons/project/wizard')
| -rw-r--r-- | addons/project/wizard/__init__.py | 32 | ||||
| -rw-r--r-- | addons/project/wizard/billing.py | 162 | ||||
| -rw-r--r-- | addons/project/wizard/close_task.py | 118 |
3 files changed, 312 insertions, 0 deletions
diff --git a/addons/project/wizard/__init__.py b/addons/project/wizard/__init__.py new file mode 100644 index 00000000000..a382e0ebfa0 --- /dev/null +++ b/addons/project/wizard/__init__.py @@ -0,0 +1,32 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id: __init__.py 843 2005-07-01 09:29:47Z nicoe $ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import billing +import close_task + diff --git a/addons/project/wizard/billing.py b/addons/project/wizard/billing.py new file mode 100644 index 00000000000..7bb5bbcb5fe --- /dev/null +++ b/addons/project/wizard/billing.py @@ -0,0 +1,162 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +import ir +from mx.DateTime import now +import pooler +import netsvc + +bill_form = """<?xml version="1.0" ?> +<form string="Billing wizard"> + <field name="journal_id"/> + <field name="sale_account_id"/> + <newline/> + <field name="task_total"/> + <field name="task_invoice"/> + <field name="invoice_num"/> + <field name="total"/> +</form>""" + +bill_fields = { + 'journal_id':{'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required': 'True'}, + 'sale_account_id':{'string':'Income account', 'type':'many2one', 'relation':'account.account', 'required': 'True'}, + 'invoice_num' : {'string':'Generated invoices', 'type': 'integer', 'readonly': 'True'}, + 'task_total' : {'string':'Number of tasks', 'type': 'integer', 'readonly': 'True'}, + 'task_invoice' : {'string':'Tasks to invoice', 'type': 'integer', 'readonly': 'True'}, + 'total' : {'string':'Total Price', 'type': 'float', 'readonly': 'True'}, +} + +ack_form = """<?xml version="1.0" ?> +<form string="Billing wizard"> + <separator string="The orders were successfully generated" /> +</form>""" + +ack_fields = {} + +def _compute_orders(self, cr, uid, data, context): + tasks = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids']) + projects = {} + tot = 0.0 + task_tot = 0 + task_inv = 0 + for task in tasks: + project = task.project_id + if not task.invoice_id and task.billable: + if project.mode == 'project': + tot += project.tariff + elif project.mode == 'effective': + tot += project.tariff * task.effective_hours + elif project.mode == 'hour': + tot += project.tariff * task.planned_hours + task_inv += 1 + projects[project.id] = projects.get(project.id, []) + [task.id] + task_tot += 1 + res = {'invoice_num': len(projects), 'total': tot, 'task_total': task_tot, 'task_invoice':task_inv} + return res + +def _do_orders(self, cr, uid, data, context): + tasks = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids']) + invoiceline = pooler.get_pool(cr.dbname).get('account.invoice.line') + customers = {} + for task in filter(lambda t: t.billable and not t.invoice_id, tasks): + if not task.project_id.id in customers: + partner = task.partner_id or task.project_id.partner_id + if not partner.id: + raise wizard.except_wizard('Error !', 'No partner defined for the task or project.') + if not task.project_id.pricelist_id.id: + raise wizard.except_wizard('Error !', 'No pricelist defined in the project definition.') + adr = pooler.get_pool(cr.dbname).get('res.partner').address_get(cr, uid, [partner.id], ['default','invoice','shipping']) + + a = partner.property_account_receivable[0] + if partner.property_payment_term: + pay_term = p.address_id.partner_id.property_payment_term[0] + else: + pay_term = False + + oid = pooler.get_pool(cr.dbname).get('account.invoice').create(cr, uid, { + 'name': task.project_id.name, + 'origin': 'Task:'+str(task.id), + 'state': 'draft', + 'partner_id': partner.id, + 'address_contact_id': adr['default'], + 'address_invoice_id': adr['invoice'], + 'account_id': a, + 'type': 'out_invoice', + 'currency_id': task.project_id.pricelist_id.currency_id.id, + 'payment_term': pay_term, + 'journal_id': data['form']['journal_id'], + #'pricelist_id': task.project_id.pricelist_id.id, + 'project_id': task.project_id.category_id.id + }) + customers[task.project_id.id] = oid + else: + oid = customers[task.project_id.id] + + if task.project_id.mode == 'project': + qty = 1 + elif task.project_id.mode == 'effective': + qty = task.effective_hours + else: + qty = task.planned_hours + + invoiceline.create(cr, uid, { + 'invoice_id': oid, + 'name': task.name, + 'account_id': data['form']['sale_account_id'], + 'price_unit': task.project_id.tariff, + 'quantity': qty, + 'invoice_line_tax_id': [(6,0, [t.id for t in task.project_id.tax_ids])] + + }) + #pooler.get_pool(cr.dbname).get('project.task').write(cr, uid, [task.id], {'invoice_id':oid}) + return { + 'domain': "[('id','in', ["+','.join(map(str,customers.values()))+"])]", + 'name': 'Invoices', + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'account.invoice', + 'view_id': False, + 'context': "{'type':'out_invoice'}", + 'type': 'ir.actions.act_window' + } + + +class wiz_bill(wizard.interface): + states = { + 'init':{ + 'actions': [_compute_orders], + 'result': {'type':'form', 'arch':bill_form, 'fields':bill_fields, 'state':[('end', 'Cancel'), ('bill', 'Ok')] }, + }, + 'bill':{ + 'actions': [], + 'result': {'type':'action', 'action':_do_orders, 'state':'end' }, + }, + } +wiz_bill('project.wiz_bill') + +# vim:noexpandtab:tw=0 diff --git a/addons/project/wizard/close_task.py b/addons/project/wizard/close_task.py new file mode 100644 index 00000000000..eb020f3c5c0 --- /dev/null +++ b/addons/project/wizard/close_task.py @@ -0,0 +1,118 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +from tools import email_send as email +import pooler + +mail_form = """<?xml version="1.0" ?> +<form string="Send mail to customer"> + <field name="email" colspan="4"/> + <field name="description" colspan="4"/> +</form>""" + +mail_fields = { + 'email': {'string': 'E-Mails', 'type': 'char', 'required': 'True', 'size':64}, + 'description': {'string':'Description', 'type':'text', 'required':'True'}, +} + +def email_send(cr, uid, ids, to_adr, description, context={}): + for task in pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, ids, context): + project = task.project_id + subject = "Task '%s' closed" % task.name + if task.user_id and task.user_id.address_id and task.user_id.address_id.email: + from_adr = task.user_id.address_id.email + signature = task.user_id.signature + else: + raise osv.except_osv('Error', "Couldn't send mail because your email address is not configured!") + + if to_adr: + val = { + 'name': task.name, + 'user_id': task.user_id.name, + 'task_id': "%d/%d" % (project.id, task.id), + 'date_start': task.date_start, + 'date_close': task.date_close, + 'state': task.state + } + header = (project.warn_header or '') % val + footer = (project.warn_footer or '') % val + body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature) + email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr]) + else: + raise osv.except_osv('Error', "Couldn't send mail because the contact for this task (%s) has no email address!"% contact.name) + +class wizard_close(wizard.interface): + def _check_complete(self, cr, uid, data, context): + task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'])[0] + if not task.project_id.warn_customer: + return 'close' + return 'mail_ask' + + def _get_data(self, cr, uid, data, context): + email = '' + task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'][0]) + partner_id = task.partner_id or task.project_id.partner_id + if partner_id and partner_id.address[0].email: + email = partner_id.address[0].email + return {'description': task.cust_desc or task.description, 'email':email} + + def _data_send(self, cr, uid, data, context): + task_obj = pooler.get_pool(cr.dbname).get('project.task') + if data['form']['email']: + description = data['form'].get('description', False) + if description: + val = {'cust_desc': description} + task_obj.write(cr, uid, [data['ids'][0]], val) + email_send(cr, uid, data['ids'], data['form']['email'], data['form']['description']) + return {} + + def _do_close(self, cr, uid, data, context): + task_obj = pooler.get_pool(cr.dbname).get('project.task') + task_obj.do_close(cr, uid, data['ids'], context) + return {} + + states = { + 'init': { + 'actions': [], + 'result': {'type':'choice', 'next_state':_check_complete} + }, + 'mail_ask': { + 'actions': [_get_data], + 'result': {'type':'form', 'arch':mail_form, 'fields':mail_fields, 'state':[('end', 'Cancel'), ('close', 'Quiet close'), ('mail_send', 'Send Message')]}, + }, + 'mail_send': { + 'actions': [_data_send], + 'result': {'type':'state', 'state':'close'}, + }, + 'close': { + 'actions': [_do_close], + 'result': {'type':'state', 'state':'end'}, + }, + } +wizard_close('project.task.close') + |
