From 004b9c9a849f2f92e3ed4eb192531780e15a0a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 9 Sep 2012 13:45:15 +0200 Subject: [PATCH 1/4] create invoice: changing journal changes company too lp bug: https://launchpad.net/bugs/1047884 fixed bzr revid: stephane.bidoul@acsone.eu-20120909114515-mbilk7jv2aj1mn9x --- addons/account/account_invoice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 15027b7a8f6..e925e87c136 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -503,8 +503,10 @@ class account_invoice(osv.osv): if journal_id: journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context) currency_id = journal.currency and journal.currency.id or journal.company_id.currency_id.id + company_id = journal.company_id.id result = {'value': { 'currency_id': currency_id, + 'company_id': company_id, } } return result From 17edcf06301179bd9d7a7d05458e7d00c67a1d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 9 Sep 2012 14:42:59 +0200 Subject: [PATCH 2/4] select account and taxes for the invoice's company instead of the user's default company when changing product or account This partially fixes lp:1048213 since the default account proposed when creating a new invoice line (in trunk only) is still from the user's company. lp bug: https://launchpad.net/bugs/1048213 fixed bzr revid: stephane.bidoul@acsone.eu-20120909124259-df6qo743sfogltf9 --- addons/account/account_invoice.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index e925e87c136..cd77b202e0e 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1365,7 +1365,10 @@ class account_invoice_line(osv.osv): 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True) } - def _default_account_id(self, cr, uid, ids, context=None): + def _default_account_id(self, cr, uid, context=None): + # XXX this gets the default account for the user's company, + # it should get the default account for the invoice's company + # however, the invoice's company does not reach this point prop = self.pool.get('ir.property').get(cr, uid, 'property_account_income_categ', 'product.category', context=context) return prop and prop.id or False @@ -1395,7 +1398,7 @@ class account_invoice_line(osv.osv): context = {} company_id = company_id if company_id != None else context.get('company_id',False) context = dict(context) - context.update({'company_id': company_id}) + context.update({'company_id': company_id, 'force_company': company_id}) if not partner_id: raise osv.except_osv(_('No Partner Defined !'),_("You must first select a partner !") ) if not product: @@ -1550,12 +1553,14 @@ class account_invoice_line(osv.osv): def onchange_account_id(self, cr, uid, ids, product_id, partner_id, inv_type, fposition_id, account_id): if not account_id: return {} - taxes = self.pool.get('account.account').browse(cr, uid, account_id).tax_ids + account = self.pool.get('account.account').browse(cr, uid, account_id) + taxes = account.tax_ids fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False tax_ids = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes) product_change_result = self.product_id_change(cr, uid, ids, product_id, False, type=inv_type, - partner_id=partner_id, fposition_id=fposition_id) + partner_id=partner_id, fposition_id=fposition_id, + company_id=account.company_id.id) unique_tax_ids = set(tax_ids) if product_change_result and 'value' in product_change_result and 'invoice_line_tax_id' in product_change_result['value']: unique_tax_ids |= set(product_change_result['value']['invoice_line_tax_id']) From 4deb1f84e7eb7f6cf23bc6dfe61c1d92b968d82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 9 Sep 2012 17:24:38 +0200 Subject: [PATCH 3/4] hr_timesheet_invoice, bill task work: use the analytic account company for the generated invoice_cost_create This makes life much easiers for people generating billings for several companies. lp bug: https://launchpad.net/bugs/1047826 fixed bzr revid: stephane.bidoul@acsone.eu-20120909152438-qax5pv4ij76asmbv --- .../wizard/hr_timesheet_invoice_create.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 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 76314e1986a..e33e88203f8 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -79,17 +79,24 @@ class account_analytic_line(osv.osv): curr_invoice = { 'name': time.strftime('%d/%m/%Y')+' - '+account.name, 'partner_id': account.partner_id.id, + 'company_id': account.company_id.id, '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, 'fiscal_position': account.partner_id.property_account_position.id } - last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context) - invoices.append(last_invoice) - + context2 = context.copy() context2['lang'] = partner.lang + # set company_id in context, so the correct default journal will be selected + context2['force_company'] = curr_invoice['company_id'] + # set force_company in context so the correct product properties are selected (eg. income account) + context2['company_id'] = curr_invoice['company_id'] + + last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context2) + invoices.append(last_invoice) + cr.execute("SELECT product_id, to_invoice, sum(unit_amount), product_uom_id, name " \ "FROM account_analytic_line as line " \ "WHERE account_id = %s " \ From 38dfccaaa08d4ee8e73e88cc17430e95313591e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 9 Sep 2012 18:59:19 +0200 Subject: [PATCH 4/4] hr_timesheet_invoice: in invoice task work, use the account default tax if the product has no taxes defined lp bug: https://launchpad.net/bugs/1048305 fixed bzr revid: stephane.bidoul@acsone.eu-20120909165919-xgxu45ugq3944gvu --- .../wizard/hr_timesheet_invoice_create.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 e33e88203f8..32ae652ca3d 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -122,11 +122,11 @@ class account_analytic_line(osv.osv): else: price = 0.0 - taxes = product.taxes_id - tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) - account_id = product.product_tmpl_id.property_account_income.id or product.categ_id.property_account_income_categ.id - if not account_id: + general_account = product.product_tmpl_id.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 = { 'price_unit': price, 'quantity': qty, @@ -137,7 +137,7 @@ class account_analytic_line(osv.osv): 'product_id': product_id, 'invoice_line_tax_id': [(6,0,tax)], 'uos_id': uom, - 'account_id': account_id, + 'account_id': general_account.id, 'account_analytic_id': account.id, }