From 37910cfc4f376ec25ffdc0348ddcda7dd64dc214 Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 13 Sep 2007 14:21:57 +0000 Subject: [PATCH] Invoice on analytic line fill now the due date bzr revid: ced-9f4f20060201acd9bb0632bbdacd816752dbe8c8 --- .../hr_timesheet_final_invoice_create.py | 22 ++++++++++++--- .../wizard/hr_timesheet_invoice_create.py | 27 ++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py index 79d8adf30cc..149050a6298 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py @@ -47,13 +47,29 @@ class final_invoice_create(wizard.interface): def _do_create(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) + 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['ids'] invoices = [] - for account in pool.get('account.analytic.account').browse(cr, uid, account_ids, context): + for account in analytic_account_obj.browse(cr, uid, account_ids, context): partner = account.partner_id amount_total=0.0 if (not partner) or not (account.pricelist_id): - raise wizard.except_wizard('Analytic account incomplete', 'Please fill in the partner and pricelist field in the analytic account:\n%s' % (account.name,)) + raise wizard.except_wizard('Analytic account incomplete', + 'Please fill in the partner and pricelist field ' + 'in the analytic account:\n%s' % (account.name,)) + + date_due = False + if partner.property_payment_term: + pterm_list= account_payment_term_obj.compute(cr, uid, + partner.property_payment_term.id, value=1, + date_ref=time.strftime('%Y-%m-%d')) + if pterm_list: + pterm_list = [line[0] for line in pterm_list] + pterm_list.sort() + date_due = pterm_list[-1] curr_invoice = { 'name': time.strftime('%D')+' - '+account.name, @@ -63,7 +79,7 @@ class final_invoice_create(wizard.interface): 'payment_term': partner.property_payment_term.id or False, 'account_id': partner.property_account_receivable.id, 'currency_id': account.pricelist_id.currency_id.id, - 'project_id': account.id + 'date_due': date_due, } last_invoice = pool.get('account.invoice').create(cr, uid, curr_invoice) invoices.append(last_invoice) 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 50d5dc25d46..686d7c6a0bd 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -48,21 +48,40 @@ class invoice_create(wizard.interface): def _do_create(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) + 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 = [] - for account in pool.get('account.analytic.account').browse(cr, uid, account_ids, context): + 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', 'Please fill in the partner and pricelist field in the analytic account:\n%s' % (account.name,)) + raise wizard.except_wizard('Analytic account incomplete', + 'Please fill in the partner and pricelist field ' + 'in the analytic account:\n%s' % (account.name,)) + + date_due = False + if partner.property_payment_term: + pterm_list= account_payment_term_obj.compute(cr, uid, + partner.property_payment_term.id, value=1, + date_ref=time.strftime('%Y-%m-%d')) + if pterm_list: + pterm_list = [line[0] for line in pterm_list] + pterm_list.sort() + date_due = pterm_list[-1] curr_invoice = { 'name': time.strftime('%D')+' - '+account.name, 'partner_id': account.partner_id.id, - 'address_contact_id': pool.get('res.partner').address_get(cr, uid, [account.partner_id.id], adr_pref=['contact'])['contact'], - 'address_invoice_id': pool.get('res.partner').address_get(cr, uid, [account.partner_id.id], adr_pref=['invoice'])['invoice'], + 'address_contact_id': res_partner_obj.address_get(cr, uid, + [account.partner_id.id], adr_pref=['contact'])['contact'], + 'address_invoice_id': res_partner_obj.address_get(cr, uid, + [account.partner_id.id], adr_pref=['invoice'])['invoice'], 'payment_term': partner.property_payment_term.id or False, 'account_id': partner.property_account_receivable.id, 'currency_id': account.pricelist_id.currency_id.id, + 'date_due': date_due, } last_invoice = pool.get('account.invoice').create(cr, uid, curr_invoice) invoices.append(last_invoice)