mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
Set correct company on invoices when working on multicompany environment
Now when working on multy company environmets the server action creates invioices with accounts belong to correct company based on contract company.
This commit is contained in:
@@ -242,8 +242,29 @@ class account_analytic_account(osv.osv):
|
||||
context['old_date'] = old_date
|
||||
context['next_date'] = datetime.datetime.strptime(
|
||||
contract.recurring_next_date or current_date, "%Y-%m-%d")
|
||||
self._prepare_invoice(
|
||||
cr, uid, contract, context=context)
|
||||
# Force company for correct evaluate domain access rules
|
||||
context['force_company'] = contract.company_id.id
|
||||
|
||||
# Create new cursor for handle multi company environments
|
||||
from openerp import pooler
|
||||
db, pool = pooler.get_db_and_pool(cr.dbname)
|
||||
cursor = db.cursor()
|
||||
try:
|
||||
this = pool.get('account.analytic.account')
|
||||
# Need to reload contract on new cursor for prevent
|
||||
# ORM optimizations use same company for load all
|
||||
# partner properties
|
||||
contract = this.browse(
|
||||
cursor, uid, contract.id, context=context
|
||||
)
|
||||
this._prepare_invoice(
|
||||
cursor, uid, contract, context=context
|
||||
)
|
||||
cursor.commit() # commit results
|
||||
except Exception:
|
||||
cursor.rollback() # error, rollback everything
|
||||
finally:
|
||||
cursor.close() # always close cursor
|
||||
|
||||
self.write(
|
||||
cr, uid, [contract.id],
|
||||
|
||||
Reference in New Issue
Block a user