From f699ba12d922bb46ee0cc77f2506e9501d4b71b4 Mon Sep 17 00:00:00 2001 From: "Bharat (OpenERP)" Date: Mon, 12 Dec 2011 12:34:03 +0530 Subject: [PATCH 1/7] [FIX] account : passed context parameter in arguments in account_invoice.py lp bug: https://launchpad.net/bugs/710533 fixed bzr revid: bde@tinyerp.com-20111212070403-6vmv02hz9qi6ibxc --- addons/account/account_invoice.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 39cc471c2f6..3034a0bada6 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -811,12 +811,12 @@ class account_invoice(osv.osv): if not inv.date_invoice: self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}) company_currency = inv.company_id.currency_id.id - # create the analytical lines - # one move line per invoice line - iml = self._get_analytic_lines(cr, uid, inv.id) - # check if taxes are all computed ctx = context.copy() ctx.update({'lang': inv.partner_id.lang}) + # create the analytical lines + # one move line per invoice line + iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx) + # check if taxes are all computed compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx) self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj) @@ -835,7 +835,7 @@ class account_invoice(osv.osv): raise osv.except_osv(_('Error !'), _("Can not create the invoice !\nThe related payment term is probably misconfigured as it gives a computed amount greater than the total invoiced amount.")) # one move line per tax line - iml += ait_obj.move_line_get(cr, uid, inv.id) + iml += ait_obj.move_line_get(cr, uid, inv.id, context=ctx) entry_type = '' if inv.type in ('in_invoice', 'in_refund'): @@ -1611,7 +1611,7 @@ class account_invoice_tax(osv.osv): t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount']) return tax_grouped - def move_line_get(self, cr, uid, invoice_id): + def move_line_get(self, cr, uid, invoice_id, context=None): res = [] cr.execute('SELECT * FROM account_invoice_tax WHERE invoice_id=%s', (invoice_id,)) for t in cr.dictfetchall(): From 25965aa35d94b6a5a95d95c3a4d5e4bad7551ae2 Mon Sep 17 00:00:00 2001 From: "Bharat (OpenERP)" Date: Wed, 14 Dec 2011 16:45:27 +0530 Subject: [PATCH 2/7] [FIX] account : replaced *args with context argument in action_move_create method of account/account_invoice.py bzr revid: bde@tinyerp.com-20111214111527-9tgwh4u9lrg5ukvy --- addons/account/account_invoice.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 3034a0bada6..7bc0c97cbb5 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -794,12 +794,13 @@ class account_invoice(osv.osv): line.append((0,0,val)) return line - def action_move_create(self, cr, uid, ids, *args): + def action_move_create(self, cr, uid, ids, context=None): """Creates invoice related analytics and financial move lines""" ait_obj = self.pool.get('account.invoice.tax') cur_obj = self.pool.get('res.currency') period_obj = self.pool.get('account.period') - context = {} + if context is None: + context = {} for inv in self.browse(cr, uid, ids): if not inv.journal_id.sequence_id: raise osv.except_osv(_('Error !'), _('Please define sequence on invoice journal')) @@ -811,13 +812,12 @@ class account_invoice(osv.osv): if not inv.date_invoice: self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}) company_currency = inv.company_id.currency_id.id - ctx = context.copy() - ctx.update({'lang': inv.partner_id.lang}) + context.update({'lang': inv.partner_id.lang}) # create the analytical lines # one move line per invoice line - iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx) + iml = self._get_analytic_lines(cr, uid, inv.id, context=context) # check if taxes are all computed - compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx) + compute_taxes = ait_obj.compute(cr, uid, inv.id, context=context) self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj) if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding/2.0): @@ -835,7 +835,7 @@ class account_invoice(osv.osv): raise osv.except_osv(_('Error !'), _("Can not create the invoice !\nThe related payment term is probably misconfigured as it gives a computed amount greater than the total invoiced amount.")) # one move line per tax line - iml += ait_obj.move_line_get(cr, uid, inv.id, context=ctx) + iml += ait_obj.move_line_get(cr, uid, inv.id, context=context) entry_type = '' if inv.type in ('in_invoice', 'in_refund'): @@ -864,10 +864,10 @@ class account_invoice(osv.osv): if totlines: res_amount_currency = total_currency i = 0 - ctx.update({'date': inv.date_invoice}) + context.update({'date': inv.date_invoice}) for t in totlines: if inv.currency_id.id != company_currency: - amount_currency = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, t[1], context=ctx) + amount_currency = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, t[1], context=context) else: amount_currency = False @@ -926,9 +926,9 @@ class account_invoice(osv.osv): 'narration':inv.comment } period_id = inv.period_id and inv.period_id.id or False - ctx.update({'company_id': inv.company_id.id}) + context.update({'company_id': inv.company_id.id}) if not period_id: - period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx) + period_ids = period_obj.find(cr, uid, inv.date_invoice, context=context) period_id = period_ids and period_ids[0] or False if period_id: move['period_id'] = period_id From 46896b6a9fab0cda308fec3b83be564c221968cd Mon Sep 17 00:00:00 2001 From: "Bharat (OpenERP)" Date: Thu, 15 Dec 2011 11:29:33 +0530 Subject: [PATCH 3/7] [FIX] kept ctx as it is for dict update on context bzr revid: bde@tinyerp.com-20111215055933-7m7f1icm1e117nd2 --- addons/account/account_invoice.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 7bc0c97cbb5..6c0d8979c36 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -812,12 +812,13 @@ class account_invoice(osv.osv): if not inv.date_invoice: self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}) company_currency = inv.company_id.currency_id.id - context.update({'lang': inv.partner_id.lang}) + ctx = context.copy() + ctx.update({'lang': inv.partner_id.lang}) # create the analytical lines # one move line per invoice line - iml = self._get_analytic_lines(cr, uid, inv.id, context=context) + iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx) # check if taxes are all computed - compute_taxes = ait_obj.compute(cr, uid, inv.id, context=context) + compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx) self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj) if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding/2.0): @@ -835,7 +836,7 @@ class account_invoice(osv.osv): raise osv.except_osv(_('Error !'), _("Can not create the invoice !\nThe related payment term is probably misconfigured as it gives a computed amount greater than the total invoiced amount.")) # one move line per tax line - iml += ait_obj.move_line_get(cr, uid, inv.id, context=context) + iml += ait_obj.move_line_get(cr, uid, inv.id, context=ctx) entry_type = '' if inv.type in ('in_invoice', 'in_refund'): @@ -864,10 +865,10 @@ class account_invoice(osv.osv): if totlines: res_amount_currency = total_currency i = 0 - context.update({'date': inv.date_invoice}) + ctx.update({'date': inv.date_invoice}) for t in totlines: if inv.currency_id.id != company_currency: - amount_currency = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, t[1], context=context) + amount_currency = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, t[1], context=ctx) else: amount_currency = False @@ -926,9 +927,9 @@ class account_invoice(osv.osv): 'narration':inv.comment } period_id = inv.period_id and inv.period_id.id or False - context.update({'company_id': inv.company_id.id}) + ctx.update({'company_id': inv.company_id.id}) if not period_id: - period_ids = period_obj.find(cr, uid, inv.date_invoice, context=context) + period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx) period_id = period_ids and period_ids[0] or False if period_id: move['period_id'] = period_id From ef580a12f61cf0ef63b3015da49596d2d9acab48 Mon Sep 17 00:00:00 2001 From: "Bharat (OpenERP)" Date: Thu, 15 Dec 2011 11:47:20 +0530 Subject: [PATCH 4/7] [FIX] passed context = context instead of blank dict {} bzr revid: bde@tinyerp.com-20111215061720-pxmkueupeoe0utt9 --- addons/account/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 6c0d8979c36..2570739917b 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -907,7 +907,7 @@ class account_invoice(osv.osv): date = inv.date_invoice or time.strftime('%Y-%m-%d') part = inv.partner_id.id - line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context={})),iml) + line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context=context)),iml) line = self.group_lines(cr, uid, iml, line, inv) From 43c36462068000a910fc2a93747f8594f02940c0 Mon Sep 17 00:00:00 2001 From: "Bharat (OpenERP)" Date: Thu, 15 Dec 2011 14:37:30 +0530 Subject: [PATCH 5/7] [FIX] added context arguments in required method of account_analytic_plans/account_analytic_plans.py, analytic_journal_billing_rate/analytic_journal_billing_rate.py, hr_timesheet_invoice/hr_timesheet_invoice.py bzr revid: bde@tinyerp.com-20111215090730-s64n85bjm5rurfrr --- addons/account_analytic_plans/account_analytic_plans.py | 4 ++-- .../analytic_journal_billing_rate.py | 4 ++-- addons/hr_timesheet_invoice/hr_timesheet_invoice.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account_analytic_plans/account_analytic_plans.py b/addons/account_analytic_plans/account_analytic_plans.py index 881a7ebc7d4..21ccb27f278 100644 --- a/addons/account_analytic_plans/account_analytic_plans.py +++ b/addons/account_analytic_plans/account_analytic_plans.py @@ -380,7 +380,7 @@ class account_invoice(osv.osv): res['analytics_id'] = x.get('analytics_id', False) return res - def _get_analytic_lines(self, cr, uid, id): + def _get_analytic_lines(self, cr, uid, id, context=None): inv = self.browse(cr, uid, [id])[0] cur_obj = self.pool.get('res.currency') invoice_line_obj = self.pool.get('account.invoice.line') @@ -391,7 +391,7 @@ class account_invoice(osv.osv): else: sign = -1 - iml = invoice_line_obj.move_line_get(cr, uid, inv.id) + iml = invoice_line_obj.move_line_get(cr, uid, inv.id, context=context) for il in iml: if il.get('analytics_id', False): diff --git a/addons/analytic_journal_billing_rate/analytic_journal_billing_rate.py b/addons/analytic_journal_billing_rate/analytic_journal_billing_rate.py index fbdf954214b..4120793df6e 100644 --- a/addons/analytic_journal_billing_rate/analytic_journal_billing_rate.py +++ b/addons/analytic_journal_billing_rate/analytic_journal_billing_rate.py @@ -100,8 +100,8 @@ hr_analytic_timesheet() class account_invoice(osv.osv): _inherit = "account.invoice" - def _get_analytic_lines(self, cr, uid, id): - iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id) + def _get_analytic_lines(self, cr, uid, id, context=None): + iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id, context=context) for il in iml: if il['account_analytic_id'] and il.get('analytic_lines', False): diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 19d08f7faf3..4b5b69c416b 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -169,8 +169,8 @@ hr_analytic_timesheet() class account_invoice(osv.osv): _inherit = "account.invoice" - def _get_analytic_lines(self, cr, uid, id): - iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id) + def _get_analytic_lines(self, cr, uid, id, context=None): + iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id, context=context) inv = self.browse(cr, uid, [id])[0] if inv.type == 'in_invoice': From 657183237a2ea3b804b737d0116821f34d1217d0 Mon Sep 17 00:00:00 2001 From: "Bharat Devnani (OpenERP)" Date: Wed, 21 Dec 2011 10:58:15 +0530 Subject: [PATCH 6/7] [FIX] account : passed context arguments at appropriate method calls and also pooled objects at the beginning of the methods bzr revid: bde@tinyerp.com-20111221052815-s669sgs9xz8i5cr1 --- addons/account/account_invoice.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 2570739917b..dedd3d97686 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -799,9 +799,13 @@ class account_invoice(osv.osv): ait_obj = self.pool.get('account.invoice.tax') cur_obj = self.pool.get('res.currency') period_obj = self.pool.get('account.period') + payment_term_obj = self.pool.get('account.payment.term') + journal_obj = self.pool.get('account.journal') + move_obj = self.pool.get('account.move') if context is None: context = {} - for inv in self.browse(cr, uid, ids): + ctx = context.copy() + for inv in self.browse(cr, uid, ids, context=ctx): if not inv.journal_id.sequence_id: raise osv.except_osv(_('Error !'), _('Please define sequence on invoice journal')) if not inv.invoice_line: @@ -810,10 +814,10 @@ class account_invoice(osv.osv): continue if not inv.date_invoice: - self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}) + self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}, context=ctx) company_currency = inv.company_id.currency_id.id - ctx = context.copy() ctx.update({'lang': inv.partner_id.lang}) + # create the analytical lines # one move line per invoice line iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx) @@ -836,7 +840,7 @@ class account_invoice(osv.osv): raise osv.except_osv(_('Error !'), _("Can not create the invoice !\nThe related payment term is probably misconfigured as it gives a computed amount greater than the total invoiced amount.")) # one move line per tax line - iml += ait_obj.move_line_get(cr, uid, inv.id, context=ctx) + iml += ait_obj.move_line_get(cr, uid, inv.id) entry_type = '' if inv.type in ('in_invoice', 'in_refund'): @@ -860,8 +864,8 @@ class account_invoice(osv.osv): name = inv['name'] or '/' totlines = False if inv.payment_term: - totlines = self.pool.get('account.payment.term').compute(cr, - uid, inv.payment_term.id, total, inv.date_invoice or False) + totlines = payment_term_obj.compute(cr, + uid, inv.payment_term.id, total, inv.date_invoice or False, context=ctx) if totlines: res_amount_currency = total_currency i = 0 @@ -912,7 +916,7 @@ class account_invoice(osv.osv): line = self.group_lines(cr, uid, iml, line, inv) journal_id = inv.journal_id.id - journal = self.pool.get('account.journal').browse(cr, uid, journal_id) + journal = journal_obj.browse(cr, uid, journal_id, context=ctx) if journal.centralisation: raise osv.except_osv(_('UserError'), _('You cannot create an invoice on a centralised journal. Uncheck the centralised counterpart box in the related journal from the configuration menu.')) @@ -936,13 +940,14 @@ class account_invoice(osv.osv): for i in line: i[2]['period_id'] = period_id - move_id = self.pool.get('account.move').create(cr, uid, move, context=context) - new_move_name = self.pool.get('account.move').browse(cr, uid, move_id).name + move_id = move_obj.create(cr, uid, move, context=context) + new_move_name = move_obj.browse(cr, uid, move_id).name # make the invoice point to that move - self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}) + self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}, context=ctx) # Pass invoice in context in method post: used if you want to get the same # account move reference when creating the same invoice after a cancelled one: - self.pool.get('account.move').post(cr, uid, [move_id], context={'invoice':inv}) + ctx.update({'invoice':inv}) + move_obj.post(cr, uid, [move_id], context=ctx) self._log_event(cr, uid, ids) return True @@ -1612,7 +1617,7 @@ class account_invoice_tax(osv.osv): t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount']) return tax_grouped - def move_line_get(self, cr, uid, invoice_id, context=None): + def move_line_get(self, cr, uid, invoice_id): res = [] cr.execute('SELECT * FROM account_invoice_tax WHERE invoice_id=%s', (invoice_id,)) for t in cr.dictfetchall(): From 9b66690af206770217cd861807076bd6b9f6c8a8 Mon Sep 17 00:00:00 2001 From: "Bharat Devnani (OpenERP)" Date: Wed, 21 Dec 2011 15:42:36 +0530 Subject: [PATCH 7/7] [FIX] account: improved the code and also assigned ctx to context argument for def action_move_create in account/account_invoice.py bzr revid: bde@tinyerp.com-20111221101236-4xppp8v82db84oq3 --- addons/account/account_invoice.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index dedd3d97686..aa4abbde301 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -804,20 +804,19 @@ class account_invoice(osv.osv): move_obj = self.pool.get('account.move') if context is None: context = {} - ctx = context.copy() - for inv in self.browse(cr, uid, ids, context=ctx): + for inv in self.browse(cr, uid, ids, context=context): if not inv.journal_id.sequence_id: raise osv.except_osv(_('Error !'), _('Please define sequence on invoice journal')) if not inv.invoice_line: raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.')) if inv.move_id: continue - + + ctx = context.copy() + ctx.update({'lang': inv.partner_id.lang}) if not inv.date_invoice: self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}, context=ctx) company_currency = inv.company_id.currency_id.id - ctx.update({'lang': inv.partner_id.lang}) - # create the analytical lines # one move line per invoice line iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx) @@ -911,7 +910,7 @@ class account_invoice(osv.osv): date = inv.date_invoice or time.strftime('%Y-%m-%d') part = inv.partner_id.id - line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context=context)),iml) + line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context=ctx)),iml) line = self.group_lines(cr, uid, iml, line, inv) @@ -940,7 +939,7 @@ class account_invoice(osv.osv): for i in line: i[2]['period_id'] = period_id - move_id = move_obj.create(cr, uid, move, context=context) + move_id = move_obj.create(cr, uid, move, context=ctx) new_move_name = move_obj.browse(cr, uid, move_id).name # make the invoice point to that move self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}, context=ctx)