From 4ff1c93a9cfcd2758de653f0950f1d60a860ca7b Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Tue, 14 Sep 2010 00:35:26 +0530 Subject: [PATCH 01/33] [FIX]: small fix for voucher bzr revid: mga@tinyerp.com-20100913190526-bthhlea1qbjljvds --- addons/account_voucher/voucher.py | 8 ++------ addons/account_voucher/voucher_payment_receipt_view.xml | 4 ---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 7d848242a1b..65ebe1261c5 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -281,17 +281,14 @@ class account_voucher(osv.osv): journal = journal_pool.browse(cr, uid, journal_id) partner = partner_pool.browse(cr, uid, partner_id) account_id = False - term_id = False if journal.type in ('sale','sale_refund'): account_id = partner.property_account_receivable.id elif journal.type in ('purchase', 'purchase_refund','expense'): account_id = partner.property_account_payable.id else: account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id - default['value'].update({ - 'account_id':account_id, - 'term_id':term_id - }) + + default['value']['account_id'] = account_id if journal.type not in ('cash', 'bank'): return default @@ -354,7 +351,6 @@ class account_voucher(osv.osv): default['value']['pre_line'] = 1 elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0: default['value']['pre_line'] = 1 - return default def onchange_date(self, cr, user, ids, date, context={}): diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index e529c624804..8656e819d6c 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -18,9 +18,7 @@ @@ -115,9 +113,7 @@ From da3be9e496193e22109f36eaeee23d4e35ec36c2 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Tue, 14 Sep 2010 13:39:17 +0530 Subject: [PATCH 02/33] [FIX]: fix a calculation of tax on change the - journal - lines cr and dr - tax id bzr revid: mga@tinyerp.com-20100914080917-5y7b4ayzchdny3o8 --- addons/account_voucher/voucher.py | 22 ++++++++++++++++--- .../voucher_sales_purchase_view.xml | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 65ebe1261c5..0b70c16568f 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -166,6 +166,7 @@ class account_voucher(osv.osv): voucher_line_pool.write(cr, uid, [line.id], {'amount':line.amount, 'untax_amount':line.untax_amount}) if not voucher.tax_id: + self.write(cr, uid, [voucher.id], {'amount':voucher_amount, 'tax_amount':0.0}) continue tax = [tax_pool.browse(cr, uid, voucher.tax_id.id)] @@ -223,11 +224,24 @@ class account_voucher(osv.osv): voucher_total += line_amount total = voucher_total + total_tax = 0.0 + if tax_id: + tax = [tax_pool.browse(cr, uid, tax_id)] + if partner_id: + partner = partner_pool.browse(cr, uid, partner_id) or False + taxes = position_pool.map_tax(cr, uid, partner and partner.property_account_position or False, tax) + tax = tax_pool.browse(cr, uid, taxes) + + if not tax[0].price_include: + for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes'): + total_tax += tax_line.get('amount') + total += total_tax res.update({ 'amount':total, 'tax_amount':total_tax }) + return { 'value':res } @@ -370,7 +384,7 @@ class account_voucher(osv.osv): } } - def onchange_journal(self, cr, uid, ids, journal_id): + def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context={}): if not journal_id: return False journal_pool = self.pool.get('account.journal') @@ -379,8 +393,10 @@ class account_voucher(osv.osv): tax_id = False if account_id and account_id.tax_ids: tax_id = account_id.tax_ids[0].id - - return {'value':{'tax_id':tax_id}} + + vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context) + vals['value'].update({'tax_id':tax_id}) + return vals def proforma_voucher(self, cr, uid, ids): self.action_move_line_create(cr, uid, ids) diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 1abf4ec1ea1..6f5cf560e09 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -19,7 +19,7 @@
- + @@ -111,7 +111,7 @@ - + From 596a6ccbc682098840db22988d579a2f9b20473a Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Tue, 14 Sep 2010 14:33:06 +0530 Subject: [PATCH 03/33] [FIX]: fix a changes for the sale receipt and account voucher search view bzr revid: mga@tinyerp.com-20100914090306-ht9iqm98goi6it9g --- addons/account_voucher/voucher.py | 8 +++---- .../voucher_sales_purchase_view.xml | 9 +++---- addons/account_voucher/voucher_view.xml | 24 +++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 0b70c16568f..3a2d49952f2 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -652,11 +652,11 @@ class account_voucher(osv.osv): type_search = { 'bank':[('type','in',['bank','cash'])], 'cash':[('type','in',['bank','cash'])], - 'sale':[('type','in',['sale','purchase_refund'])], - 'purchase':[('type','in',['purchase','sale_refund'])], + 'sale':[('type','in',['sale','sale_refund'])], + 'purchase':[('type','in',['purchase','purchase_refund'])], 'expense':[('type','in',['purchase'])], - 'sale_refund':[('type','in',['sale','purchase_refund'])], - 'purchase_refund':[('type','in',['purchase','sale_refund'])] + 'sale_refund':[('type','in',['sale','sale_refund'])], + 'purchase_refund':[('type','in',['purchase','purchase_refund'])] } domain = type_search.get(context.get('journal_type')) journal_list = journal_pool.name_search(cr, uid, '', domain) diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 6f5cf560e09..a91536b845c 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -19,7 +19,7 @@ - + @@ -50,6 +50,7 @@ + @@ -85,7 +86,7 @@ Sales Receipt account.voucher.open form - [('journal_id.type','in',['sale','purchase_refund']), ('type','=','sale')] + [('journal_id.type','in',['sale','sale_refund']), ('type','=','sale')] {'journal_type':'sale', 'type':'sale'} new @@ -111,7 +112,7 @@ - + @@ -171,7 +172,7 @@ Vendor Bills account.voucher.open form - [('journal_id.type','in',['purchase','sale_refund']), ('type','=','purchase')] + [('journal_id.type','in',['purchase','purchase_refund']), ('type','=','purchase')] {'journal_type':'purchase', 'type':'purchase'} new diff --git a/addons/account_voucher/voucher_view.xml b/addons/account_voucher/voucher_view.xml index 6e8e4ffe690..6b7e073b5f9 100644 --- a/addons/account_voucher/voucher_view.xml +++ b/addons/account_voucher/voucher_view.xml @@ -104,6 +104,12 @@ + + + + + + @@ -111,12 +117,6 @@ - - - - - - @@ -143,18 +143,18 @@ + + + + + + - - - - - - From 884738450c60e68cab42536c79864c2870d60d29 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Tue, 14 Sep 2010 16:28:16 +0530 Subject: [PATCH 04/33] [IMP] analytic: Improve the query to get values in chart of analytic account bzr revid: psi@tinyerp.co.in-20100914105816-scg8i63oiuyuvwhu --- addons/analytic/analytic.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index 26f57c984c0..eef25f665d8 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -70,7 +70,7 @@ class account_analytic_account(osv.osv): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date', False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency<0 and a.id IN %s GROUP BY a.id",(tuple(parent_ids),)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount<0 and a.id IN %s GROUP BY a.id",(tuple(parent_ids),)) r = dict(cr.fetchall()) return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, r, context) @@ -90,7 +90,7 @@ class account_analytic_account(osv.osv): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency>0 and a.id IN %s GROUP BY a.id" ,(tuple(parent_ids),)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount>0 and a.id IN %s GROUP BY a.id" ,(tuple(parent_ids),)) r = dict(cr.fetchall()) return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, r, context=context) @@ -111,11 +111,10 @@ class account_analytic_account(osv.osv): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id IN %s GROUP BY a.id",(tuple(parent_ids),)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id IN %s GROUP BY a.id",(tuple(parent_ids),)) for account_id, sum in cr.fetchall(): res[account_id] = sum - return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context=context) def _quantity_calc(self, cr, uid, ids, name, arg, context=None): @@ -182,10 +181,10 @@ class account_analytic_account(osv.osv): 'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', select=2), 'child_ids': fields.one2many('account.analytic.account', 'parent_id', 'Child Accounts'), 'line_ids': fields.one2many('account.analytic.line', 'account_id', 'Analytic Entries'), - 'balance' : fields.function(_balance_calc, method=True, type='float', string='Balance',store=True), - 'debit' : fields.function(_debit_calc, method=True, type='float', string='Debit',store=True), - 'credit' : fields.function(_credit_calc, method=True, type='float', string='Credit',store=True), - 'quantity': fields.function(_quantity_calc, method=True, type='float', string='Quantity',store=True), + 'balance' : fields.function(_balance_calc, method=True, type='float', string='Balance'), + 'debit' : fields.function(_debit_calc, method=True, type='float', string='Debit'), + 'credit' : fields.function(_credit_calc, method=True, type='float', string='Credit'), + 'quantity': fields.function(_quantity_calc, method=True, type='float', string='Quantity'), 'quantity_max': fields.float('Maximum Quantity', help='Sets the higher limit of quantity of hours.'), 'partner_id' : fields.many2one('res.partner', 'Associated Partner'), 'contact_id' : fields.many2one('res.partner.address', 'Contact'), @@ -216,7 +215,7 @@ class account_analytic_account(osv.osv): 'user_id' : lambda self, cr, uid, ctx : uid, 'partner_id': lambda self, cr, uid, ctx: ctx.get('partner_id', False), 'contact_id': lambda self, cr, uid, ctx: ctx.get('contact_id', False), - 'date_start': time.strftime('%Y-%m-%d') + 'date_start': time.strftime('%Y-%m-%d') } def check_recursion(self, cr, uid, ids, parent=None): From 3db30f732752ade5c9c2e3f43b43414620071ca3 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Tue, 14 Sep 2010 16:49:20 +0530 Subject: [PATCH 05/33] [FIX]: fix a problem of the voucher entry lines, and improvements [FIX]: fix a small problem on calculation tax after saving the voucher bzr revid: mga@tinyerp.com-20100914111920-tt0zp5jl4ml22bb9 --- addons/account_voucher/voucher.py | 26 +++++++++---------- .../voucher_sales_purchase_view.xml | 13 +++++----- addons/account_voucher/voucher_view.xml | 2 ++ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 3a2d49952f2..95100bbbe91 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -134,8 +134,7 @@ class account_voucher(osv.osv): ],'Payment', select=True, readonly=True, states={'draft':[('readonly',False)]}), 'tax_id':fields.many2one('account.tax', 'Tax', readonly=True, states={'draft':[('readonly',False)]}), 'pre_line':fields.boolean('Previous Payments ?', required=False), - 'date_due': fields.date('Due Date'), -# 'term_id':fields.many2one('account.payment.term', 'Term', required=False), + 'date_due': fields.date('Due Date', readonly=True, states={'draft':[('readonly',False)]}), } _defaults = { 'period_id': _get_period, @@ -216,10 +215,7 @@ class account_voucher(osv.osv): for line in line_ids: line_amount = 0.0 - if line[1]: - line_amount = voucher_line_pool.browse(cr, uid, line[1]).untax_amount - else: - line_amount = line[2].get('amount') + line_amount = line[2].get('amount') voucher_line_ids += [line[1]] voucher_total += line_amount @@ -238,10 +234,9 @@ class account_voucher(osv.osv): total += total_tax res.update({ - 'amount':total, + 'amount':total or voucher_total, 'tax_amount':total_tax }) - return { 'value':res } @@ -512,7 +507,7 @@ class account_voucher(osv.osv): if credit < 0: debit = -credit credit = 0.0 - + move_line = { 'name':inv.name or '/', 'debit':debit, @@ -526,7 +521,9 @@ class account_voucher(osv.osv): 'date':inv.date, 'date_maturity':inv.date_due } - master_line = move_line_pool.create(cr, uid, move_line) + + if (debit == 0.0 or credit == 0.0 or debit+credit > 0) and (debit > 0.0 or credit > 0.0): + master_line = move_line_pool.create(cr, uid, move_line) rec_list_ids = [] line_total = debit - credit @@ -540,6 +537,7 @@ class account_voucher(osv.osv): if not line.amount: continue amount = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount) + move_line = { 'journal_id':inv.journal_id.id, 'period_id':inv.period_id.id, @@ -548,6 +546,7 @@ class account_voucher(osv.osv): 'move_id':move_id, 'partner_id':inv.partner_id.id, 'currency_id':inv.currency_id.id, + 'amount_currency':line.amount, 'analytic_account_id':line.account_analytic_id and line.account_analytic_id.id or False, 'quantity':1, 'credit':0.0, @@ -568,11 +567,10 @@ class account_voucher(osv.osv): line_total -= amount move_line['credit'] = amount - if inv.tax_id: + if inv.tax_id and inv.type in ('sale', 'purchase'): move_line.update({ 'account_tax_id':inv.tax_id.id, }) - master_line = move_line_pool.create(cr, uid, move_line) if line.move_line_id.id: rec_ids = [master_line, line.move_line_id.id] @@ -590,7 +588,7 @@ class account_voucher(osv.osv): 'debit':diff<0 and -diff or 0.0, } account_id = False - if inv.journal_id.type in ('sale','sale_refund', 'cash','bank'): + if inv.journal_id.type in ('sale','sale_refund', 'cash', 'bank'): account_id = inv.partner_id.property_account_receivable.id else: account_id = inv.partner_id.property_account_payable.id @@ -601,7 +599,7 @@ class account_voucher(osv.osv): 'move_id': move_id, 'state':'posted' }) - move_pool.post(cr, uid, [move_id], context={}) + #move_pool.post(cr, uid, [move_id], context={}) for rec_ids in rec_list_ids: if len(rec_ids) >= 2: move_line_pool.reconcile_partial(cr, uid, rec_ids) diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index a91536b845c..8692cb3373d 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -7,7 +7,7 @@ account.voucher form [('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt'), ('partner_id','=',partner_id)] - {'journal_type':'bank', 'type':'receipt', 'partner_id': partner_id} + {'journal_type':'bank', 'type':'receipt', 'partner_id': partner_id, 'referance':referance} new @@ -54,7 +54,7 @@ -