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
In the last commit we used a new cursor for this problem, but in this time we make a browse for each contract like Pedro Baeza proposed
This commit is contained in:
@@ -243,30 +243,14 @@ class AccountAnalyticAccount(orm.Model):
|
|||||||
context['next_date'] = new_date
|
context['next_date'] = new_date
|
||||||
# Force company for correct evaluate domain access rules
|
# Force company for correct evaluate domain access rules
|
||||||
context['force_company'] = contract.company_id.id
|
context['force_company'] = contract.company_id.id
|
||||||
|
# Re-read contract with correct company
|
||||||
# Create new cursor for handle multi company environments
|
contract = self.browse(cr, uid, contract.id, context=context)
|
||||||
from openerp import pooler
|
self._prepare_invoice(
|
||||||
db, pool = pooler.get_db_and_pool(cr.dbname)
|
cr, uid, contract, context=context
|
||||||
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(
|
self.write(
|
||||||
cr, uid, [contract.id],
|
cr, uid, [contract.id],
|
||||||
{'recurring_next_date': new_date.strftime('%Y-%m-%d')},
|
{'recurring_next_date': new_date.strftime('%Y-%m-%d')},
|
||||||
context=context)
|
context=context
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user