From 490a86d21b8d205d34cd90e8994b7d3432b3e143 Mon Sep 17 00:00:00 2001 From: "Pinakin Nayi (OpenERP)" Date: Wed, 12 Jun 2013 14:15:04 +0530 Subject: [PATCH 1/3] [IMP]hr_timesheet_invoice : product is not mandatory at the time of creation invoice of expenses and in invoice set product price on the basic of analytic line not on the basis of product price bzr revid: pna@tinyerp.com-20130612084504-dmgz3t3vlyruooje --- .../hr_timesheet_invoice.py | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index bc3b532ce61..26e29baadbb 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -174,7 +174,10 @@ class account_analytic_line(osv.osv): data = {} journal_types = {} + price = 0.0 for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context): + price = abs(line.amount) + line_name = line.name if line.journal_id.type not in journal_types: journal_types[line.journal_id.type] = set() journal_types[line.journal_id.type].add(line.account_id.id) @@ -226,37 +229,42 @@ class account_analytic_line(osv.osv): 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. 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: - factor_name += ' - ' + factor.customer_name - - ctx = context.copy() - ctx.update({'uom':uom}) - - price = self._get_invoice_price(cr, uid, account, product_id, user_id, qty, ctx) - - general_account = product.property_account_income or product.categ_id.property_account_income_categ - if not general_account: - 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) + factor_name = line_name + ' - ' + factor.customer_name 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, - } + 'price_unit': price, + 'quantity': qty, + 'discount':factor.factor, + 'invoice_id': last_invoice, + 'name': factor_name, + 'uos_id': uom, + 'account_analytic_id': account.id, + } + if product: + factor_name = product_obj.name_get(cr, uid, [product_id], context=context2)[0][1] + if factor.customer_name: + factor_name += ' - ' + factor.customer_name + ctx = context.copy() + ctx.update({'uom':uom}) + + if price <= 0.0 : + price = self._get_invoice_price(cr, uid, account, product_id, user_id, qty, ctx) + + general_account = product.property_account_income or product.categ_id.property_account_income_categ + if not general_account: + 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.update({ + 'price_unit': price, + 'invoice_line_tax_id': [(6,0,tax )], + 'name': factor_name, + 'product_id': product_id, + 'invoice_line_tax_id': [(6,0,tax)], + 'account_id': general_account.id, + }) + # # Compute for lines # From 9caf5ef64cc7f8c80ae061403da84dff9d0aae45 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 21 Jun 2013 14:26:39 +0200 Subject: [PATCH 2/3] [FIX] hr_timehseet_invoice: allow use force product bzr revid: mat@openerp.com-20130621122639-sfcb7q1pwquiz46l --- .../hr_timesheet_invoice.py | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 26e29baadbb..9993625353d 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -176,7 +176,7 @@ class account_analytic_line(osv.osv): journal_types = {} price = 0.0 for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context): - price = abs(line.amount) + price += abs(line.amount) line_name = line.name if line.journal_id.type not in journal_types: journal_types[line.journal_id.type] = set() @@ -208,7 +208,6 @@ class account_analytic_line(osv.osv): 'date_due': date_due, 'fiscal_position': account.partner_id.property_account_position.id } - context2 = context.copy() context2['lang'] = partner.lang # set company_id in context, so the correct default journal will be selected @@ -232,23 +231,24 @@ class account_analytic_line(osv.osv): factor = invoice_factor_obj.browse(cr, uid, factor_id, context=context2) factor_name = line_name + ' - ' + factor.customer_name curr_line = { - 'price_unit': price, - 'quantity': qty, - 'discount':factor.factor, - 'invoice_id': last_invoice, - 'name': factor_name, - 'uos_id': uom, - 'account_analytic_id': account.id, - } + 'price_unit': price, + 'quantity': qty, + 'discount': factor.factor, + 'invoice_id': last_invoice, + 'name': factor_name, + 'uos_id': uom, + 'account_analytic_id': account.id, + } if product: factor_name = product_obj.name_get(cr, uid, [product_id], context=context2)[0][1] if factor.customer_name: factor_name += ' - ' + factor.customer_name - ctx = context.copy() - ctx.update({'uom':uom}) + ctx = context.copy() + ctx.update({'uom': uom}) - if price <= 0.0 : + # check force product + if price <= 0.0 or data.get('product'): price = self._get_invoice_price(cr, uid, account, product_id, user_id, qty, ctx) general_account = product.property_account_income or product.categ_id.property_account_income_categ @@ -257,14 +257,14 @@ 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) curr_line.update({ - 'price_unit': price, - 'invoice_line_tax_id': [(6,0,tax )], - 'name': factor_name, - 'product_id': product_id, - 'invoice_line_tax_id': [(6,0,tax)], - 'account_id': general_account.id, - }) - + 'price_unit': price, + 'invoice_line_tax_id': [(6,0,tax )], + 'name': factor_name, + 'product_id': product_id, + 'invoice_line_tax_id': [(6,0,tax)], + 'account_id': general_account.id, + }) + # # Compute for lines # From b3bba607e6fa54be4f9898c846bdf9f5411b0c08 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 21 Jun 2013 14:47:37 +0200 Subject: [PATCH 3/3] allow using price of 0 or less for expense bzr revid: mat@openerp.com-20130621124737-zo01u5jbafnb0ges --- addons/hr_timesheet_invoice/hr_timesheet_invoice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 9993625353d..a3db06c49ab 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -176,7 +176,7 @@ class account_analytic_line(osv.osv): journal_types = {} price = 0.0 for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context): - price += abs(line.amount) + price += line.amount*-1 line_name = line.name if line.journal_id.type not in journal_types: journal_types[line.journal_id.type] = set() @@ -229,7 +229,7 @@ class account_analytic_line(osv.osv): product_id = data['product'][0] product = product_obj.browse(cr, uid, product_id, context=context2) factor = invoice_factor_obj.browse(cr, uid, factor_id, context=context2) - factor_name = line_name + ' - ' + factor.customer_name + factor_name = factor.customer_name and line_name + ' - ' + factor.customer_name or line_name curr_line = { 'price_unit': price, 'quantity': qty, @@ -248,7 +248,7 @@ class account_analytic_line(osv.osv): ctx.update({'uom': uom}) # check force product - if price <= 0.0 or data.get('product'): + if data.get('product'): price = self._get_invoice_price(cr, uid, account, product_id, user_id, qty, ctx) general_account = product.property_account_income or product.categ_id.property_account_income_categ