[FIX] account: install a chart of account on another company
1. Create odoo instance with "--without-demo=ALL" option. 2. Install Accounting module. 3. Add Chart of Accounts manually (e.g. code 111111 Bank and Cash and 222222 Other Income) 4. Create Journal. 5. Create Journal Entries. 6. Activate multi-company. 7. Set new company to current user and set the new company as current company. 8. Install accounting localization: Accounting >> Configuration >> Settings >> Install More Packages >> (install any localization module) Before this commit, there was an error because when installing any module, the environment in which it happens is in uid = 1 and doesn't have a context anymore Thus, when arriving in the charts of accounts code, the env's user is still 1 Which doesn't mean anything in V12, since it is the system user After this commit, the user is retrieved from the request OPW 1911677 closes odoo/odoo#29310
This commit is contained in:
@@ -5,6 +5,7 @@ from odoo import api, fields, models, _
|
||||
from odoo import SUPERUSER_ID
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import pycompat
|
||||
from odoo.http import request
|
||||
|
||||
import logging
|
||||
|
||||
@@ -164,7 +165,13 @@ class AccountChartTemplate(models.Model):
|
||||
of accounts had been created for it yet.
|
||||
"""
|
||||
self.ensure_one()
|
||||
company = self.env.user.company_id
|
||||
if request:
|
||||
company_id = request.env.user.company_id.id
|
||||
company = self.env['res.company'].browse(company_id)
|
||||
else:
|
||||
# fallback to company of current user, most likely __system__
|
||||
# (won't work well for multi-company)
|
||||
company = self.env.user.company_id
|
||||
# If we don't have any chart of account on this company, install this chart of account
|
||||
if not company.chart_template_id:
|
||||
self.load_for_current_company(15.0, 15.0)
|
||||
@@ -178,7 +185,13 @@ class AccountChartTemplate(models.Model):
|
||||
rights.
|
||||
"""
|
||||
self.ensure_one()
|
||||
company = self.env.user.company_id
|
||||
if request:
|
||||
company_id = request.env.user.company_id.id
|
||||
company = self.env['res.company'].browse(company_id)
|
||||
else:
|
||||
# fallback to company of current user, most likely __system__
|
||||
# (won't work well for multi-company)
|
||||
company = self.env.user.company_id
|
||||
# Ensure everything is translated to the company's language, not the user's one.
|
||||
self = self.with_context(lang=company.partner_id.lang)
|
||||
if not self.env.user._is_admin():
|
||||
|
||||
Reference in New Issue
Block a user