diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 0c16fb4ffd4..1f795b6e97f 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -73,7 +73,7 @@ account_analytic_account() class account_analytic_line(osv.osv): _inherit = 'account.analytic.line' _columns = { - 'invoice_id': fields.many2one('account.invoice', 'Invoice'), + 'invoice_id': fields.many2one('account.invoice', 'Invoice', ondelete="set null"), 'to_invoice': fields.many2one('hr_timesheet_invoice.factor', 'Invoicing'), } diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py index 65ca5c31a07..7bc8583f676 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -36,6 +36,13 @@ class invoice_create(wizard.interface): def _get_accounts(self, cr, uid, data, context): if not len(data['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) + 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 IN (%s)"% (','.join(map(str,data['ids'])),)) account_ids = cr.fetchall() return {'accounts': [x[0] for x in account_ids]}