From 63f4f786a28efc5517e8c70f87830e5218d26121 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Mon, 12 Nov 2012 19:20:43 +0530 Subject: [PATCH 1/6] [IMP] merge the timesheet line for the same product. bzr revid: nco@tinyerp.com-20121112135043-qrqbcf0m731rw7nx --- .../wizard/hr_timesheet_invoice_create.py | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) 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 695d589ee2e..eb91f7faa3b 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -112,6 +112,7 @@ class account_analytic_line(osv.osv): "AND id IN %s AND to_invoice IS NOT NULL " \ "GROUP BY product_id, user_id, to_invoice, product_uom_id, name", (account.id, tuple(ids),)) + curr_line = {} for product_id, user_id, factor_id, qty, uom, line_name in cr.fetchall(): if data.get('product'): product_id = data['product'][0] @@ -133,49 +134,52 @@ class account_analytic_line(osv.osv): raise osv.except_osv(_("Configuration Error!"), _("Please define income account for product '%s'.") % product.name) taxes = product.taxes_id or general_account.tax_ids tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) - curr_line = { - 'price_unit': price, - 'quantity': qty, - 'discount':factor.factor, - 'invoice_line_tax_id': [(6,0,tax )], - 'invoice_id': last_invoice, - 'name': factor_name, - 'product_id': product_id, - 'invoice_line_tax_id': [(6,0,tax)], - 'uos_id': uom, - 'account_id': general_account.id, - 'account_analytic_id': account.id, - } - - # - # Compute for lines - # - cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id)) - - line_ids = cr.dictfetchall() - note = [] - for line in line_ids: - # set invoice_line_note - details = [] - if data.get('date', False): - details.append(line['date']) - if data.get('time', False): - if line['product_uom_id']: - details.append("%s %s" % (line['unit_amount'], product_uom_obj.browse(cr, uid, [line['product_uom_id']],context2)[0].name)) - else: - details.append("%s" % (line['unit_amount'], )) - if data.get('name', False): - details.append(line['name']) - note.append(u' - '.join(map(lambda x: unicode(x) or '',details))) - - if note: - curr_line['name'] += "\n" + ("\n".join(map(lambda x: unicode(x) or '',note))) - invoice_line_obj.create(cr, uid, curr_line, context=context) - cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id IN %s", (last_invoice, account.id, tuple(ids))) + invoice_line_ids = invoice_line_obj.search(cr, uid, [('product_id', '=', product.id), ('invoice_id', '=', last_invoice)]) + if invoice_line_ids: + invoice_line_obj.write(cr, uid, invoice_line_ids, {'quantity': qty+ curr_line.get('quantity')}) + else: + curr_line = { + 'price_unit': price, + 'quantity': qty, + 'discount':factor.factor, + 'invoice_line_tax_id': [(6,0,tax )], + 'invoice_id': last_invoice, + 'name': factor_name, + 'product_id': product_id, + 'invoice_line_tax_id': [(6,0,tax)], + 'uos_id': uom, + 'account_id': general_account.id, + 'account_analytic_id': account.id, + } + + # + # Compute for lines + # + cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id)) + + line_ids = cr.dictfetchall() + note = [] + for line in line_ids: + # set invoice_line_note + details = [] + if data.get('date', False): + details.append(line['date']) + if data.get('time', False): + if line['product_uom_id']: + details.append("%s %s" % (line['unit_amount'], product_uom_obj.browse(cr, uid, [line['product_uom_id']],context2)[0].name)) + else: + details.append("%s" % (line['unit_amount'], )) + if data.get('name', False): + details.append(line['name']) + note.append(u' - '.join(map(lambda x: unicode(x) or '',details))) + + if note: + curr_line['name'] += "\n" + ("\n".join(map(lambda x: unicode(x) or '',note))) + invoice_line_obj.create(cr, uid, curr_line, context=context) + cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id IN %s", (last_invoice, account.id, tuple(ids))) invoice_obj.button_reset_taxes(cr, uid, [last_invoice], context) return invoices - # # TODO: check unit of measure !!! # From 65cd11f10d1edac1aa9d81cd461c3ea21423a8e6 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Fri, 16 Nov 2012 18:50:55 +0530 Subject: [PATCH 2/6] [FIX] fix the worng invoice amount. bzr revid: nco@tinyerp.com-20121116132055-sfyjk47onvxl8wle --- addons/account_analytic_analysis/account_analytic_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py index 0fffde30719..02f3dbc7852 100644 --- a/addons/account_analytic_analysis/account_analytic_analysis.py +++ b/addons/account_analytic_analysis/account_analytic_analysis.py @@ -300,7 +300,7 @@ class account_analytic_account(osv.osv): res[account.id] = 0.0 line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False), ('journal_id.type', '=', 'general')], context=context) for line in lines_obj.browse(cr, uid, line_ids, context=context): - res[account.id] += line.invoice_id.amount_untaxed + res[account.id] = line.invoice_id.amount_untaxed return res def _remaining_ca_calc(self, cr, uid, ids, name, arg, context=None): From 10e3cfe72c8a30088aaa63125a08d4a8f9e34bee Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Mon, 19 Nov 2012 12:08:28 +0530 Subject: [PATCH 3/6] [FIX] set analytic account line on expense line. bzr revid: nco@tinyerp.com-20121119063828-g86valoppqs9h27f --- .../analytic_contract_hr_expense.py | 1 + addons/hr_expense/hr_expense_view.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py index 8f24f12808b..35177ee3a66 100644 --- a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py +++ b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py @@ -136,6 +136,7 @@ class account_analytic_account(osv.osv): 'name': name, 'view_type': 'form', 'view_mode': 'tree,form', + 'context':{'analytic_account':ids[0]}, 'domain' : domain, 'res_model': 'hr.expense.expense', 'nodestroy': True, diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index d4b7cbae1ce..22ed48dc15c 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -85,7 +85,7 @@ - +
From 8a59fa019959122b3dcb7a523382be3a1b4f4d03 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Tue, 20 Nov 2012 17:21:27 +0530 Subject: [PATCH 4/6] [IMP] correct the total for contract and fix problem of number of qty in for the same product. bzr revid: nco@tinyerp.com-20121120115127-4zb0hpcqpzvqffc2 --- .../account_analytic_analysis.py | 5 +- .../wizard/hr_timesheet_invoice_create.py | 84 ++++++++++--------- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py index 02f3dbc7852..06e2fd2bb18 100644 --- a/addons/account_analytic_analysis/account_analytic_analysis.py +++ b/addons/account_analytic_analysis/account_analytic_analysis.py @@ -296,11 +296,14 @@ class account_analytic_account(osv.osv): def _timesheet_ca_invoiced_calc(self, cr, uid, ids, name, arg, context=None): lines_obj = self.pool.get('account.analytic.line') res = {} + inv_ids = [] for account in self.browse(cr, uid, ids, context=context): res[account.id] = 0.0 line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False), ('journal_id.type', '=', 'general')], context=context) for line in lines_obj.browse(cr, uid, line_ids, context=context): - res[account.id] = line.invoice_id.amount_untaxed + if line.invoice_id not in inv_ids: + inv_ids.append(line.invoice_id) + res[account.id] += line.invoice_id.amount_untaxed return res def _remaining_ca_calc(self, cr, uid, ids, name, arg, context=None): 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 eb91f7faa3b..8c68abf272c 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -113,6 +113,7 @@ class account_analytic_line(osv.osv): "GROUP BY product_id, user_id, to_invoice, product_uom_id, name", (account.id, tuple(ids),)) curr_line = {} + total_qty = 0 for product_id, user_id, factor_id, qty, uom, line_name in cr.fetchall(): if data.get('product'): product_id = data['product'][0] @@ -135,48 +136,49 @@ class account_analytic_line(osv.osv): taxes = product.taxes_id or general_account.tax_ids tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) invoice_line_ids = invoice_line_obj.search(cr, uid, [('product_id', '=', product.id), ('invoice_id', '=', last_invoice)]) + total_qty +=qty if invoice_line_ids: - invoice_line_obj.write(cr, uid, invoice_line_ids, {'quantity': qty+ curr_line.get('quantity')}) - else: - curr_line = { - 'price_unit': price, - 'quantity': qty, - 'discount':factor.factor, - 'invoice_line_tax_id': [(6,0,tax )], - 'invoice_id': last_invoice, - 'name': factor_name, - 'product_id': product_id, - 'invoice_line_tax_id': [(6,0,tax)], - 'uos_id': uom, - 'account_id': general_account.id, - 'account_analytic_id': account.id, - } - - # - # Compute for lines - # - cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id)) - - line_ids = cr.dictfetchall() - note = [] - for line in line_ids: - # set invoice_line_note - details = [] - if data.get('date', False): - details.append(line['date']) - if data.get('time', False): - if line['product_uom_id']: - details.append("%s %s" % (line['unit_amount'], product_uom_obj.browse(cr, uid, [line['product_uom_id']],context2)[0].name)) - else: - details.append("%s" % (line['unit_amount'], )) - if data.get('name', False): - details.append(line['name']) - note.append(u' - '.join(map(lambda x: unicode(x) or '',details))) - - if note: - curr_line['name'] += "\n" + ("\n".join(map(lambda x: unicode(x) or '',note))) - invoice_line_obj.create(cr, uid, curr_line, context=context) - cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id IN %s", (last_invoice, account.id, tuple(ids))) + invoice_line_obj.write(cr, uid, invoice_line_ids, {'quantity': total_qty}) + continue + curr_line = { + 'price_unit': price, + 'quantity': qty, + 'discount':factor.factor, + 'invoice_line_tax_id': [(6,0,tax )], + 'invoice_id': last_invoice, + 'name': factor_name, + 'product_id': product_id, + 'invoice_line_tax_id': [(6,0,tax)], + 'uos_id': uom, + 'account_id': general_account.id, + 'account_analytic_id': account.id, + } + + # + # Compute for lines + # + cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id)) + + line_ids = cr.dictfetchall() + note = [] + for line in line_ids: + # set invoice_line_note + details = [] + if data.get('date', False): + details.append(line['date']) + if data.get('time', False): + if line['product_uom_id']: + details.append("%s %s" % (line['unit_amount'], product_uom_obj.browse(cr, uid, [line['product_uom_id']],context2)[0].name)) + else: + details.append("%s" % (line['unit_amount'], )) + if data.get('name', False): + details.append(line['name']) + note.append(u' - '.join(map(lambda x: unicode(x) or '',details))) + + if note: + curr_line['name'] += "\n" + ("\n".join(map(lambda x: unicode(x) or '',note))) + invoice_line_obj.create(cr, uid, curr_line, context=context) + cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id IN %s", (last_invoice, account.id, tuple(ids))) invoice_obj.button_reset_taxes(cr, uid, [last_invoice], context) return invoices From 542b048b3ffa8dbe1d16662a39892ea0a7d4e5b5 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Wed, 21 Nov 2012 11:16:47 +0530 Subject: [PATCH 5/6] [IMP] group the lines for similar produt/ratio by changeing query. bzr revid: nco@tinyerp.com-20121121054647-2k7hvqyz0s4ah45h --- .../wizard/hr_timesheet_invoice_create.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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 8c68abf272c..2612765b362 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -106,20 +106,19 @@ class account_analytic_line(osv.osv): last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context2) invoices.append(last_invoice) - cr.execute("SELECT product_id, user_id, to_invoice, sum(unit_amount), product_uom_id, name " \ + cr.execute("SELECT product_id, user_id, to_invoice, sum(unit_amount), product_uom_id " \ "FROM account_analytic_line as line " \ "WHERE account_id = %s " \ "AND id IN %s AND to_invoice IS NOT NULL " \ - "GROUP BY product_id, user_id, to_invoice, product_uom_id, name", (account.id, tuple(ids),)) + "GROUP BY product_id, user_id, to_invoice, product_uom_id", (account.id, tuple(ids),)) curr_line = {} - total_qty = 0 - for product_id, user_id, factor_id, qty, uom, line_name in cr.fetchall(): + for product_id, user_id, factor_id, qty, uom in cr.fetchall(): if data.get('product'): product_id = data['product'][0] product = product_obj.browse(cr, uid, product_id, context=context2) if not product: - raise osv.except_osv(_('Error!'), _('There is no product defined for the line %s. Please select one or force the product through the wizard.') % (line_name)) + raise osv.except_osv(_('Error!'), _('There is no product defined for the line. Please select one or force the product through the wizard.')) factor = invoice_factor_obj.browse(cr, uid, factor_id, context=context2) factor_name = product_obj.name_get(cr, uid, [product_id], context=context2)[0][1] if factor.customer_name: @@ -136,10 +135,6 @@ class account_analytic_line(osv.osv): taxes = product.taxes_id or general_account.tax_ids tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) invoice_line_ids = invoice_line_obj.search(cr, uid, [('product_id', '=', product.id), ('invoice_id', '=', last_invoice)]) - total_qty +=qty - if invoice_line_ids: - invoice_line_obj.write(cr, uid, invoice_line_ids, {'quantity': total_qty}) - continue curr_line = { 'price_unit': price, 'quantity': qty, From 11bf67d192a466b94897e93faf68be5eb0373e38 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Wed, 21 Nov 2012 11:55:29 +0530 Subject: [PATCH 6/6] [IMP] improve waring and remove unused lines. bzr revid: nco@tinyerp.com-20121121062529-lt0yf4imqajvel47 --- .../wizard/hr_timesheet_invoice_create.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 2612765b362..cf946f1321f 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -112,13 +112,12 @@ class account_analytic_line(osv.osv): "AND id IN %s AND to_invoice IS NOT NULL " \ "GROUP BY product_id, user_id, to_invoice, product_uom_id", (account.id, tuple(ids),)) - curr_line = {} for product_id, user_id, factor_id, qty, uom in cr.fetchall(): if data.get('product'): product_id = data['product'][0] product = product_obj.browse(cr, uid, product_id, context=context2) if not product: - raise osv.except_osv(_('Error!'), _('There is no product defined for the line. Please select one or force the product through the wizard.')) + raise osv.except_osv(_('Error!'), _('There is no product defined. Please select one or force the product through the wizard.')) factor = invoice_factor_obj.browse(cr, uid, factor_id, context=context2) factor_name = product_obj.name_get(cr, uid, [product_id], context=context2)[0][1] if factor.customer_name: @@ -134,7 +133,6 @@ class account_analytic_line(osv.osv): raise osv.except_osv(_("Configuration Error!"), _("Please define income account for product '%s'.") % product.name) taxes = product.taxes_id or general_account.tax_ids tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) - invoice_line_ids = invoice_line_obj.search(cr, uid, [('product_id', '=', product.id), ('invoice_id', '=', last_invoice)]) curr_line = { 'price_unit': price, 'quantity': qty,