diff options
| author | Yannick Tivisse <yti@odoo.com> | 2019-05-22 09:03:55 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-05-29 08:09:15 +0000 |
| commit | f5dfe4727c086c7577da2aef12c2d3548ba938a3 (patch) | |
| tree | 8af04c84c18ded0c1ed48c7c61640021dd9d24cb /addons | |
| parent | 11cab26fb0f2167bfccfc3f11db10ff308f067b4 (diff) | |
[IMP] api.py: Rename company_id/company_ids into company/companies
The goal is to be coherent with the user property.
Actually, company_id and company_ids on the environment are no fields.
Calling env.company_id returns a browse record, not an id.
Diffstat (limited to 'addons')
188 files changed, 445 insertions, 445 deletions
diff --git a/addons/account/__init__.py b/addons/account/__init__.py index b68cc24e7db..8a862f5d090 100644 --- a/addons/account/__init__.py +++ b/addons/account/__init__.py @@ -13,7 +13,7 @@ SYSCOHADA_LIST = ['BJ', 'BF', 'CM', 'CF', 'KM', 'CG', 'CI', 'GA', 'GN', 'GW', 'G def _auto_install_l10n(cr, registry): #check the country of the main company (only) and eventually load some module needed in that country env = api.Environment(cr, SUPERUSER_ID, {}) - country_code = env.company_id.country_id.code + country_code = env.company.country_id.code if country_code: #auto install localization module(s) if available module_list = [] diff --git a/addons/account/controllers/onboarding.py b/addons/account/controllers/onboarding.py index 1fd3044623b..01eeb07fc81 100644 --- a/addons/account/controllers/onboarding.py +++ b/addons/account/controllers/onboarding.py @@ -10,7 +10,7 @@ class OnboardingController(http.Controller): It can be empty if the user has closed it or if he doesn't have the permission to see it. """ - company = request.env.company_id + company = request.env.company if not request.env.user._is_admin() or \ company.account_invoice_onboarding_state == 'closed': return {} @@ -27,7 +27,7 @@ class OnboardingController(http.Controller): """ Returns the `banner` for the account dashboard onboarding panel. It can be empty if the user has closed it or if he doesn't have the permission to see it. """ - company = request.env.company_id + company = request.env.company if not request.env.user._is_admin() or \ company.account_dashboard_onboarding_state == 'closed': diff --git a/addons/account/models/account.py b/addons/account/models/account.py index fa36ce46c5a..0931f8ebd3d 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -208,7 +208,7 @@ class AccountAccount(models.Model): 'account_id', 'tax_id', string='Default Taxes', context={'append_type_to_tax_name': True}) note = fields.Text('Internal Notes') company_id = fields.Many2one('res.company', string='Company', required=True, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting") group_id = fields.Many2one('account.group') @@ -507,7 +507,7 @@ class AccountJournalGroup(models.Model): _description = "Account Journal Group" name = fields.Char(required=True, translate=True) - company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company) account_journal_ids = fields.Many2many('account.journal', string="Journals") sequence = fields.Integer(default=10) @@ -574,7 +574,7 @@ class AccountJournal(models.Model): #groups_id = fields.Many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', string='Groups') currency_id = fields.Many2one('res.currency', help='The currency used to enter statement', string="Currency", oldname='currency') - company_id = fields.Many2one('res.company', string='Company', required=True, index=True, default=lambda self: self.env.company_id, + company_id = fields.Many2one('res.company', string='Company', required=True, index=True, default=lambda self: self.env.company, help="Company related to this journal") refund_sequence = fields.Boolean(string='Dedicated Credit Note Sequence', help="Check this box if you don't want to share the same sequence for invoices and credit notes made from this journal", default=False) @@ -877,7 +877,7 @@ class AccountJournal(models.Model): @api.model def create(self, vals): - company_id = vals.get('company_id', self.env.company_id.id) + company_id = vals.get('company_id', self.env.company.id) if vals.get('type') in ('bank', 'cash'): # For convenience, the name can be inferred from account number if not vals.get('name') and 'bank_acc_number' in vals: @@ -949,16 +949,16 @@ class AccountJournal(models.Model): @api.depends('company_id') def _belong_to_company(self): for journal in self: - journal.belong_to_company = (journal.company_id.id == self.env.company_id.id) + journal.belong_to_company = (journal.company_id.id == self.env.company.id) @api.multi def _search_company_journals(self, operator, value): if value: - recs = self.search([('company_id', operator, self.env.company_id.id)]) + recs = self.search([('company_id', operator, self.env.company.id)]) elif operator == '=': - recs = self.search([('company_id', '!=', self.env.company_id.id)]) + recs = self.search([('company_id', '!=', self.env.company.id)]) else: - recs = self.search([('company_id', operator, self.env.company_id.id)]) + recs = self.search([('company_id', operator, self.env.company.id)]) return [('id', 'in', [x.id for x in recs])] @api.multi @@ -1030,7 +1030,7 @@ class AccountTax(models.Model): e.g 200 * (1 - 10%) = 180 (price included) """) active = fields.Boolean(default=True, help="Set active to false to hide the tax without removing it.") - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) children_tax_ids = fields.Many2many('account.tax', 'account_tax_filiation_rel', 'parent_tax', 'child_tax', string='Children Taxes') sequence = fields.Integer(required=True, default=1, help="The sequence field is used to define order in which the tax lines are applied.") @@ -1257,7 +1257,7 @@ class AccountTax(models.Model): }], } """ if not self: - company = self.env.company_id + company = self.env.company else: company = self[0].company_id diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index c1cfa7aef0b..8cea4c9bd92 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -101,7 +101,7 @@ class AccountBankStatement(models.Model): @api.model def _default_journal(self): journal_type = self.env.context.get('journal_type', False) - company_id = self.env.company_id.id + company_id = self.env.company.id if journal_type: journals = self.env['account.journal'].search([('type', '=', journal_type), ('company_id', '=', company_id)]) if journals: @@ -145,7 +145,7 @@ class AccountBankStatement(models.Model): journal_id = fields.Many2one('account.journal', string='Journal', required=True, states={'confirm': [('readonly', True)]}, default=_default_journal) journal_type = fields.Selection(related='journal_id.type', help="Technical field used for usability purposes", readonly=False) company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', store=True, readonly=True, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) total_entry_encoding = fields.Monetary('Transactions Subtotal', compute='_end_balance', store=True, help="Total of transaction lines.") balance_end = fields.Monetary('Computed Balance', compute='_end_balance', store=True, help='Balance as calculated based on Opening Balance and transaction lines') diff --git a/addons/account/models/account_fiscal_year.py b/addons/account/models/account_fiscal_year.py index e5af53a2eb0..633388559e9 100644 --- a/addons/account/models/account_fiscal_year.py +++ b/addons/account/models/account_fiscal_year.py @@ -17,7 +17,7 @@ class AccountFiscalYear(models.Model): date_to = fields.Date(string='End Date', required=True, help='Ending Date, included in the fiscal year.') company_id = fields.Many2one('res.company', string='Company', required=True, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) @api.constrains('date_from', 'date_to', 'company_id') def _check_dates(self): diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 754a82d9f46..9213b347573 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -49,7 +49,7 @@ class AccountInvoice(models.Model): def _get_default_incoterm(self): - return self.env.company_id.incoterm_id + return self.env.company.incoterm_id @api.one @api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'tax_line_ids.amount_rounding', @@ -88,7 +88,7 @@ class AccountInvoice(models.Model): return self.env['account.journal'].browse(self._context.get('default_journal_id')) inv_type = self._context.get('type', 'out_invoice') inv_types = inv_type if isinstance(inv_type, list) else [inv_type] - company_id = self._context.get('company_id', self.env.company_id.id) + company_id = self._context.get('company_id', self.env.company.id) domain = [ ('type', 'in', [TYPE2JOURNAL[ty] for ty in inv_types if ty in TYPE2JOURNAL]), ('company_id', '=', company_id), @@ -102,12 +102,12 @@ class AccountInvoice(models.Model): @api.model def _default_currency(self): journal = self._default_journal() - return journal.currency_id or journal.company_id.currency_id or self.env.company_id.currency_id + return journal.currency_id or journal.company_id.currency_id or self.env.company.currency_id def _default_comment(self): invoice_type = self.env.context.get('type', 'out_invoice') if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms'): - return self.env.company_id.invoice_terms + return self.env.company.invoice_terms def _get_aml_for_amount_residual(self): """ Get the aml to consider to compute the amount residual of invoices """ @@ -377,7 +377,7 @@ class AccountInvoice(models.Model): domain="[('type', 'in', {'out_invoice': ['sale'], 'out_refund': ['sale'], 'in_refund': ['purchase'], 'in_invoice': ['purchase']}.get(type, [])), ('company_id', '=', company_id)]") company_id = fields.Many2one('res.company', string='Company', change_default=True, required=True, readonly=True, states={'draft': [('readonly', False)]}, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) reconciled = fields.Boolean(string='Paid/Reconciled', store=True, readonly=True, compute='_compute_residual', help="It indicates that the invoice has been paid and the journal entry of the invoice has been reconciled with one or several journal entries of payment.") @@ -744,7 +744,7 @@ class AccountInvoice(models.Model): def message_post(self, **kwargs): if self.env.context.get('mark_invoice_as_sent'): self.filtered(lambda inv: not inv.sent).write({'sent': True}) - self.env.company_id.set_onboarding_step_done('account_onboarding_sample_invoice_state') + self.env.company.set_onboarding_step_done('account_onboarding_sample_invoice_state') return super(AccountInvoice, self.with_context(mail_post_autofollow=True)).message_post(**kwargs) @api.model @@ -1843,7 +1843,7 @@ class AccountInvoiceLine(models.Model): if self.invoice_id.currency_id and self.invoice_id.currency_id != self.invoice_id.company_id.currency_id: currency = self.invoice_id.currency_id date = self.invoice_id._get_currency_rate_date() - price_subtotal_signed = currency._convert(price_subtotal_signed, self.invoice_id.company_id.currency_id, self.company_id or self.env.company_id, date or fields.Date.today()) + price_subtotal_signed = currency._convert(price_subtotal_signed, self.invoice_id.company_id.currency_id, self.company_id or self.env.company, date or fields.Date.today()) sign = self.invoice_id.type in ['in_refund', 'out_refund'] and -1 or 1 self.price_subtotal_signed = price_subtotal_signed * sign @@ -1941,7 +1941,7 @@ class AccountInvoiceLine(models.Model): self.ensure_one() # Keep only taxes of the company - company_id = self.company_id or self.env.company_id + company_id = self.company_id or self.env.company if self.invoice_id.type in ('out_invoice', 'out_refund'): taxes = self.product_id.taxes_id.filtered(lambda r: r.company_id == company_id) or self.account_id.tax_ids or self.invoice_id.company_id.account_sale_tax_id diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index d6d56067152..cf1f40f7a94 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -317,7 +317,7 @@ class account_journal(models.Model): curr_cache = {} if curr_cache is None else curr_cache for result in results_dict: cur = self.env['res.currency'].browse(result.get('currency')) - company = self.env['res.company'].browse(result.get('company_id')) or self.env.company_id + company = self.env['res.company'].browse(result.get('company_id')) or self.env.company rslt_count += 1 date = result.get('date_invoice') or fields.Date.today() diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b6c78252ab6..8fb43c81d3d 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -26,7 +26,7 @@ class AccountMove(models.Model): def default_get(self, fields): rec = super(AccountMove, self).default_get(fields) if not rec.get('journal_id'): - rec.update({'journal_id': self.env['account.journal'].search([('type', '=', 'general'), ('company_id', '=', self.env.company_id.id)], limit=1).id}) + rec.update({'journal_id': self.env['account.journal'].search([('type', '=', 'general'), ('company_id', '=', self.env.company.id)], limit=1).id}) return rec @api.multi @@ -117,7 +117,7 @@ class AccountMove(models.Model): @api.multi def _get_default_journal(self): if self.env.context.get('default_journal_type'): - return self.env['account.journal'].search([('company_id', '=', self.env.company_id.id), ('type', '=', self.env.context['default_journal_type'])], limit=1).id + return self.env['account.journal'].search([('company_id', '=', self.env.company.id), ('type', '=', self.env.context['default_journal_type'])], limit=1).id @api.multi @api.depends('line_ids.partner_id') @@ -418,7 +418,7 @@ class AccountMove(models.Model): def assert_balanced(self): if not self.ids: return True - prec = self.env.company_id.currency_id.decimal_places + prec = self.env.company.currency_id.decimal_places self._cr.execute("""\ SELECT move_id @@ -1382,7 +1382,7 @@ class AccountMoveLine(models.Model): currency_id = False date = self.env.context.get('date') or fields.Date.today() company = self.env.context.get('company_id') - company = self.env['res.company'].browse(company) if company else self.env.company_id + company = self.env['res.company'].browse(company) if company else self.env.company if src_currency and src_currency != company_currency: amount_currency = amount amount = src_currency._convert(amount, company_currency, company, date) @@ -1438,7 +1438,7 @@ class AccountMoveLine(models.Model): 'move_id': move_line.id, 'user_id': move_line.invoice_id.user_id.id or self._uid, 'partner_id': move_line.partner_id.id, - 'company_id': move_line.analytic_account_id.company_id.id or self.env.company_id.id, + 'company_id': move_line.analytic_account_id.company_id.id or self.env.company.id, }) return result @@ -1463,7 +1463,7 @@ class AccountMoveLine(models.Model): 'ref': self.ref, 'move_id': self.id, 'user_id': self.invoice_id.user_id.id or self._uid, - 'company_id': distribution.account_id.company_id.id or self.env.company_id.id, + 'company_id': distribution.account_id.company_id.id or self.env.company.id, } @api.model diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 197bee837f7..b8858ef04cb 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -72,7 +72,7 @@ class account_payment(models.Model): partner_id = fields.Many2one('res.partner', string='Partner', tracking=True, readonly=True, states={'draft': [('readonly', False)]}) amount = fields.Monetary(string='Payment Amount', required=True, readonly=True, states={'draft': [('readonly', False)]}, tracking=True) - currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company_id.currency_id) + currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company.currency_id) payment_date = fields.Date(string='Payment Date', default=fields.Date.context_today, required=True, readonly=True, states={'draft': [('readonly', False)]}, copy=False, tracking=True) communication = fields.Char(string='Memo', readonly=True, states={'draft': [('readonly', False)]}) journal_id = fields.Many2one('account.journal', string='Payment Journal', required=True, readonly=True, states={'draft': [('readonly', False)]}, tracking=True, domain=[('type', 'in', ('bank', 'cash'))]) @@ -314,7 +314,7 @@ class account_payment(models.Model): if payment_currency == currency: total += amount_total else: - total += payment_currency._convert(amount_total, currency, self.env.company_id, self.payment_date or fields.Date.today()) + total += payment_currency._convert(amount_total, currency, self.env.company, self.payment_date or fields.Date.today()) return total @api.multi @@ -717,7 +717,7 @@ class payment_register(models.TransientModel): if 'invoice_ids' not in rec: rec['invoice_ids'] = [(6, 0, invoices.ids)] if 'journal_id' not in rec: - rec['journal_id'] = self.env['account.journal'].search([('company_id', '=', self.env.company_id.id), ('type', 'in', ('bank', 'cash'))], limit=1).id + rec['journal_id'] = self.env['account.journal'].search([('company_id', '=', self.env.company.id), ('type', 'in', ('bank', 'cash'))], limit=1).id if 'payment_method_id' not in rec: if invoices[0].type in ('out_invoice', 'in_refund'): domain = [('payment_type', '=', 'inbound')] diff --git a/addons/account/models/account_payment_term.py b/addons/account/models/account_payment_term.py index 4756b1ec22c..bec851e8d6b 100644 --- a/addons/account/models/account_payment_term.py +++ b/addons/account/models/account_payment_term.py @@ -42,7 +42,7 @@ class AccountPaymentTerm(models.Model): if self.env.context.get('currency_id'): currency = self.env['res.currency'].browse(self.env.context['currency_id']) else: - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id for line in self.line_ids: if line.value == 'fixed': amt = sign * currency.round(line.value_amount) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 53280b2732f..b3f12709e8a 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -13,7 +13,7 @@ class AccountReconcileModel(models.Model): # Base fields. name = fields.Char(string='Name', required=True) sequence = fields.Integer(required=True, default=10) - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) rule_type = fields.Selection(selection=[ ('writeoff_button', _('Manually create a write-off on clicked button.')), diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index ebfdde3757f..7c1503ba0c4 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -171,7 +171,7 @@ class AccountChartTemplate(models.Model): if request and 'allowed_company_ids' in dir(request): company = self.env['res.company'].browse(request.allowed_company_ids[0]) else: - company = self.env.company_id + company = self.env.company # If we don't have any chart of account on this company, install this chart of account if not company.chart_template_id and not self.existing_accounting(company): self.load_for_current_company(15.0, 15.0) @@ -189,7 +189,7 @@ class AccountChartTemplate(models.Model): if request and 'allowed_company_ids' in dir(request): company = self.env['res.company'].browse(request.allowed_company_ids[0]) else: - company = self.env.company_id + company = self.env.company # 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(): diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 093730ebf31..b730ee001b3 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -313,7 +313,7 @@ Best Regards,''')) @api.model def setting_init_fiscal_year_action(self): """ Called by the 'Fiscal Year Opening' button of the setup bar.""" - company = self.env.company_id + company = self.env.company company.create_op_move_if_non_existant() new_wizard = self.env['account.financial.year.op'].create({'company_id': company.id}) view_id = self.env.ref('account.setup_financial_year_opening_form').id @@ -331,7 +331,7 @@ Best Regards,''')) @api.model def setting_chart_of_accounts_action(self): """ Called by the 'Chart of Accounts' button of the setup bar.""" - company = self.env.company_id + company = self.env.company company.set_onboarding_step_done('account_setup_coa_state') # If an opening move has already been posted, we open the tree view showing all the accounts @@ -455,25 +455,25 @@ Best Regards,''')) @api.model def action_close_account_invoice_onboarding(self): """ Mark the invoice onboarding panel as closed. """ - self.env.company_id.account_invoice_onboarding_state = 'closed' + self.env.company.account_invoice_onboarding_state = 'closed' @api.model def action_close_account_dashboard_onboarding(self): """ Mark the dashboard onboarding panel as closed. """ - self.env.company_id.account_dashboard_onboarding_state = 'closed' + self.env.company.account_dashboard_onboarding_state = 'closed' @api.model def action_open_account_onboarding_invoice_layout(self): """ Onboarding step for the invoice layout. """ action = self.env.ref('account.action_open_account_onboarding_invoice_layout').read()[0] - action['res_id'] = self.env.company_id.id + action['res_id'] = self.env.company.id return action @api.model def action_open_account_onboarding_sale_tax(self): """ Onboarding step for the invoice layout. """ action = self.env.ref('account.action_open_account_onboarding_sale_tax').read()[0] - action['res_id'] = self.env.company_id.id + action['res_id'] = self.env.company.id return action @api.model @@ -482,7 +482,7 @@ Best Regards,''')) # use current user as partner partner = self.env.user.partner_id - company_id = self.env.company_id.id + company_id = self.env.company.id # try to find an existing sample invoice sample_invoice = self.env['account.invoice'].search( [('company_id', '=', company_id), @@ -490,7 +490,7 @@ Best Regards,''')) if len(sample_invoice) == 0: # If there are no existing accounts or no journal, fail - account = self.env.company_id.get_chart_of_accounts_or_fail() + account = self.env.company.get_chart_of_accounts_or_fail() journal = self.env['account.journal'].search([('company_id', '=', company_id)], limit=1) if len(journal) == 0: diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index b5df07cf8f5..4a706f93c7b 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -204,7 +204,7 @@ class ResPartner(models.Model): @api.multi def _credit_debit_get(self): - tables, where_clause, where_params = self.env['account.move.line'].with_context(company_id=self.env.company_id.id)._query_get() + tables, where_clause, where_params = self.env['account.move.line'].with_context(company_id=self.env.company.id)._query_get() where_params = [tuple(self.ids)] + where_params if where_clause: where_clause = 'AND ' + where_clause @@ -263,7 +263,7 @@ class ResPartner(models.Model): self.total_invoiced = 0.0 return True - user_currency_id = self.env.company_id.currency_id.id + user_currency_id = self.env.company.currency_id.id all_partners_and_children = {} all_partner_ids = [] for partner in self: @@ -309,7 +309,7 @@ class ResPartner(models.Model): partner.contracts_count = AccountAnalyticAccount.search_count([('partner_id', '=', partner.id)]) def get_followup_lines_domain(self, date, overdue_only=False, only_unblocked=False): - domain = [('reconciled', '=', False), ('account_id.deprecated', '=', False), ('account_id.internal_type', '=', 'receivable'), '|', ('debit', '!=', 0), ('credit', '!=', 0), ('company_id', '=', self.env.company_id.id)] + domain = [('reconciled', '=', False), ('account_id.deprecated', '=', False), ('account_id.internal_type', '=', 'receivable'), '|', ('debit', '!=', 0), ('credit', '!=', 0), ('company_id', '=', self.env.company.id)] if only_unblocked: domain += [('blocked', '=', False)] if self.ids: @@ -362,14 +362,14 @@ class ResPartner(models.Model): @api.multi def mark_as_reconciled(self): self.env['account.partial.reconcile'].check_access_rights('write') - return self.sudo().with_context(company_id=self.env.company_id.id).write({'last_time_entries_checked': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) + return self.sudo().with_context(company_id=self.env.company.id).write({'last_time_entries_checked': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) @api.one def _get_company_currency(self): if self.company_id: self.currency_id = self.sudo().company_id.currency_id else: - self.currency_id = self.env.company_id.currency_id + self.currency_id = self.env.company.currency_id credit = fields.Monetary(compute='_credit_debit_get', search=_credit_search, string='Total Receivable', help="Total amount this customer owes you.") @@ -448,7 +448,7 @@ class ResPartner(models.Model): if self.company_id: company = self.company_id else: - company = self.env.company_id + company = self.env.company return {'domain': {'property_account_position_id': [('company_id', 'in', [company.id, False])]}} def can_edit_vat(self): diff --git a/addons/account/models/product.py b/addons/account/models/product.py index 0bf02614962..655b457bbf0 100644 --- a/addons/account/models/product.py +++ b/addons/account/models/product.py @@ -23,9 +23,9 @@ class ProductTemplate(models.Model): _inherit = "product.template" taxes_id = fields.Many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', help="Default taxes used when selling the product.", string='Customer Taxes', - domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company_id.account_sale_tax_id) + domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company.account_sale_tax_id) supplier_taxes_id = fields.Many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes', help='Default taxes used when buying the product.', - domain=[('type_tax_use', '=', 'purchase')], default=lambda self: self.env.company_id.account_purchase_tax_id) + domain=[('type_tax_use', '=', 'purchase')], default=lambda self: self.env.company.account_purchase_tax_id) property_account_income_id = fields.Many2one('account.account', company_dependent=True, string="Income Account", oldname="property_account_income", domain=[('deprecated', '=', False)], diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py index 9e7fd8a0c1d..0d6577fe34c 100644 --- a/addons/account/models/reconciliation_widget.py +++ b/addons/account/models/reconciliation_widget.py @@ -361,7 +361,7 @@ class AccountReconciliation(models.AbstractModel): is_partner and ' ' or "AND at.type <> 'payable' AND at.type <> 'receivable'", account_type and "AND at.type = %(account_type)s" or '', res_ids and 'AND ' + res_alias + '.id in %(res_ids)s' or '', - self.env.company_id.id, + self.env.company.id, is_partner and 'AND l.partner_id = p.id' or ' ', aml_ids and 'AND l.id IN %(aml_ids)s' or '', is_partner and 'l.partner_id, p.id,' or ' ', diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index c54dc0b2f3a..fe30a1c33e9 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -142,7 +142,7 @@ class ResConfigSettings(models.TransientModel): def _onchange_tax_exigibility(self): res = {} tax = self.env['account.tax'].search([ - ('company_id', '=', self.env.company_id.id), ('tax_exigibility', '=', 'on_payment') + ('company_id', '=', self.env.company.id), ('tax_exigibility', '=', 'on_payment') ], limit=1) if not self.tax_exigibility and tax: self.tax_exigibility = True diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py index 36070e760b7..85a6f4bfcfb 100644 --- a/addons/account/report/account_aged_partner_balance.py +++ b/addons/account/report/account_aged_partner_balance.py @@ -46,7 +46,7 @@ class ReportAgedPartnerBalance(models.AbstractModel): total = [] partner_clause = '' cr = self.env.cr - user_company = self.env.company_id + user_company = self.env.company user_currency = user_company.currency_id company_ids = self._context.get('company_ids') or [user_company.id] move_state = ['draft', 'posted'] @@ -140,7 +140,7 @@ class ReportAgedPartnerBalance(models.AbstractModel): if partial_line.max_date <= date_from: line_amount -= partial_line.company_id.currency_id._convert(partial_line.amount, user_currency, user_company, date_from) - if not self.env.company_id.currency_id.is_zero(line_amount): + if not self.env.company.currency_id.is_zero(line_amount): partners_amount[partner_id] += line_amount lines.setdefault(partner_id, []) lines[partner_id].append({ @@ -178,7 +178,7 @@ class ReportAgedPartnerBalance(models.AbstractModel): for partial_line in line.matched_credit_ids: if partial_line.max_date <= date_from: line_amount -= partial_line.company_id.currency_id._convert(partial_line.amount, user_currency, user_company, date_from) - if not self.env.company_id.currency_id.is_zero(line_amount): + if not self.env.company.currency_id.is_zero(line_amount): undue_amounts[partner_id] += line_amount lines.setdefault(partner_id, []) lines[partner_id].append({ @@ -198,7 +198,7 @@ class ReportAgedPartnerBalance(models.AbstractModel): total[6] = total[6] + undue_amt values['direction'] = undue_amt - if not float_is_zero(values['direction'], precision_rounding=self.env.company_id.currency_id.rounding): + if not float_is_zero(values['direction'], precision_rounding=self.env.company.currency_id.rounding): at_least_one_amount = True for i in range(5): @@ -208,7 +208,7 @@ class ReportAgedPartnerBalance(models.AbstractModel): # Adding counter total[(i)] = total[(i)] + (during and during[0] or 0) values[str(i)] = during and during[0] or 0.0 - if not float_is_zero(values[str(i)], precision_rounding=self.env.company_id.currency_id.rounding): + if not float_is_zero(values[str(i)], precision_rounding=self.env.company.currency_id.rounding): at_least_one_amount = True values['total'] = sum([values['direction']] + [values[str(i)] for i in range(5)]) ## Add for total diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index e431a183259..594a49d831e 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -15,10 +15,10 @@ class AccountInvoiceReport(models.Model): def _compute_amounts_in_user_currency(self): """Compute the amounts in the currency of the user """ - user_currency_id = self.env.company_id.currency_id + user_currency_id = self.env.company.currency_id currency_rate_id = self.env['res.currency.rate'].search([ ('rate', '=', 1), - '|', ('company_id', '=', self.env.company_id.id), ('company_id', '=', False)], limit=1) + '|', ('company_id', '=', self.env.company.id), ('company_id', '=', False)], limit=1) base_currency_id = currency_rate_id.currency_id for record in self: date = record.date or fields.Date.today() diff --git a/addons/account/tests/account_test_classes.py b/addons/account/tests/account_test_classes.py index 57441be8652..3bf7d53f970 100644 --- a/addons/account/tests/account_test_classes.py +++ b/addons/account/tests/account_test_classes.py @@ -27,7 +27,7 @@ class AccountingTestCase(HttpCase): :param property_name: The name of the property. ''' - company_id = self.env.company_id + company_id = self.env.company field_id = self.env['ir.model.fields'].search( [('model', '=', 'product.template'), ('name', '=', property_name)], limit=1) property_id = self.env['ir.property'].search([ diff --git a/addons/account/tests/test_account_customer_invoice.py b/addons/account/tests/test_account_customer_invoice.py index 4ee92c99762..5334151eebb 100644 --- a/addons/account/tests/test_account_customer_invoice.py +++ b/addons/account/tests/test_account_customer_invoice.py @@ -108,7 +108,7 @@ class TestAccountCustomerInvoice(AccountTestUsers): def test_customer_invoice_tax(self): - self.env.company_id.tax_calculation_rounding_method = 'round_globally' + self.env.company.tax_calculation_rounding_method = 'round_globally' payment_term = self.env.ref('account.account_payment_term_advance') journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0] @@ -169,7 +169,7 @@ class TestAccountCustomerInvoice(AccountTestUsers): self.assertAlmostEquals(invoice.amount_untaxed, sum([x.base for x in invoice.tax_line_ids])) def test_customer_invoice_tax_refund(self): - company = self.env.company_id + company = self.env.company tax_account = self.env['account.account'].create({ 'name': 'TAX', 'code': 'TAX', diff --git a/addons/account/tests/test_bank_statement_reconciliation.py b/addons/account/tests/test_bank_statement_reconciliation.py index dd3554839fb..0e0e2ceadfa 100644 --- a/addons/account/tests/test_bank_statement_reconciliation.py +++ b/addons/account/tests/test_bank_statement_reconciliation.py @@ -70,7 +70,7 @@ class TestBankStatementReconciliation(AccountingTestCase): vals = {'partner_id': self.partner.id, 'type': 'out_invoice', 'name': '-', - 'currency_id': self.env.company_id.currency_id.id, + 'currency_id': self.env.company.currency_id.id, } # new creates a temporary record to apply the on_change afterwards invoice = self.i_model.new(vals) diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 8571ec138c7..62d414fdf54 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -935,7 +935,7 @@ class TestReconciliationExec(TestReconciliation): account_type = ['receivable'] report_date_to = time.strftime('%Y') + '-07-17' partner = self.env['res.partner'].create({'name': 'AgedPartner'}) - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id invoice = self.create_invoice_partner(currency_id=currency.id, partner_id=partner.id) journal = self.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'THE'}) @@ -1044,7 +1044,7 @@ class TestReconciliationExec(TestReconciliation): AgedReport = self.env['report.account.report_agedpartnerbalance'].with_context(include_nullified_amount=True) account_type = ['receivable'] partner = self.env['res.partner'].create({'name': 'AgedPartner'}) - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id invoice = self.create_invoice_partner(currency_id=currency.id, partner_id=partner.id) journal = self.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'THE'}) @@ -1546,7 +1546,7 @@ class TestReconciliationExec(TestReconciliation): def test_reconciliation_to_check(self): partner = self.env['res.partner'].create({'name': 'UncertainPartner'}) - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id invoice = self.create_invoice_partner(currency_id=currency.id, partner_id=partner.id) journal = self.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'THE', 'update_posted':True}) diff --git a/addons/account/wizard/account_invoice_send.py b/addons/account/wizard/account_invoice_send.py index 5525b908af3..17e539de230 100644 --- a/addons/account/wizard/account_invoice_send.py +++ b/addons/account/wizard/account_invoice_send.py @@ -10,8 +10,8 @@ class AccountInvoiceSend(models.TransientModel): _inherits = {'mail.compose.message':'composer_id'} _description = 'Account Invoice Send' - is_email = fields.Boolean('Email', default=lambda self: self.env.company_id.invoice_is_email) - is_print = fields.Boolean('Print', default=lambda self: self.env.company_id.invoice_is_print) + is_email = fields.Boolean('Email', default=lambda self: self.env.company.invoice_is_email) + is_print = fields.Boolean('Print', default=lambda self: self.env.company.invoice_is_print) printed = fields.Boolean('Is Printed', default=False) invoice_ids = fields.Many2many('account.invoice', 'account_invoice_account_invoice_send_rel', string='Invoices') composer_id = fields.Many2one('mail.compose.message', string='Composer', required=True, ondelete='cascade') diff --git a/addons/account/wizard/account_report_common.py b/addons/account/wizard/account_report_common.py index 8e3ecee1700..dad0acd868d 100644 --- a/addons/account/wizard/account_report_common.py +++ b/addons/account/wizard/account_report_common.py @@ -7,7 +7,7 @@ class AccountCommonReport(models.TransientModel): _name = "account.common.report" _description = "Account Common Report" - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) journal_ids = fields.Many2many('account.journal', string='Journals', required=True, default=lambda self: self.env['account.journal'].search([('company_id', '=', self.company_id.id)])) date_from = fields.Date(string='Start Date') date_to = fields.Date(string='End Date') diff --git a/addons/account/wizard/setup_wizards.py b/addons/account/wizard/setup_wizards.py index 88b1f5b5657..c9d52ee6e02 100644 --- a/addons/account/wizard/setup_wizards.py +++ b/addons/account/wizard/setup_wizards.py @@ -42,7 +42,7 @@ class FinancialYearOpeningWizard(models.TransientModel): @api.multi def action_save_onboarding_fiscal_year(self): - self.env.company_id.set_onboarding_step_done('account_setup_fy_data_state') + self.env.company.set_onboarding_step_done('account_setup_fy_data_state') class SetupBarBankConfigWizard(models.TransientModel): @@ -71,7 +71,7 @@ class SetupBarBankConfigWizard(models.TransientModel): def _onchange_new_journal_code(self): for record in self: if not record.linked_journal_id: - record.new_journal_code = self.env['account.journal'].get_next_bank_cash_default_code('bank', self.env.company_id.id) + record.new_journal_code = self.env['account.journal'].get_next_bank_cash_default_code('bank', self.env.company.id) else: record.new_journal_code = self.linked_journal_id.code @@ -81,7 +81,7 @@ class SetupBarBankConfigWizard(models.TransientModel): company, so we always inject the corresponding partner when creating the model. """ - vals['partner_id'] = self.env.company_id.partner_id.id + vals['partner_id'] = self.env.company.partner_id.id return super(SetupBarBankConfigWizard, self).create(vals) @api.onchange('linked_journal_id') @@ -105,7 +105,7 @@ class SetupBarBankConfigWizard(models.TransientModel): for record in self: selected_journal = record.linked_journal_id if record.num_journals_without_account == 0: - company = self.env.company_id + company = self.env.company selected_journal = self.env['account.journal'].create({ 'name': record.new_journal_name, 'code': record.new_journal_code, diff --git a/addons/account/wizard/wizard_tax_adjustments.py b/addons/account/wizard/wizard_tax_adjustments.py index af573d9fef5..a394c240ffe 100644 --- a/addons/account/wizard/wizard_tax_adjustments.py +++ b/addons/account/wizard/wizard_tax_adjustments.py @@ -19,7 +19,7 @@ class TaxAdjustments(models.TransientModel): credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, domain=[('deprecated', '=', False)]) amount = fields.Monetary(currency_field='company_currency_id', required=True) adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", store=False, required=True) - company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.company_id.currency_id) + company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.company.currency_id) tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'adjustment')], required=True) @api.multi diff --git a/addons/account_bank_statement_import/account_bank_statement_import.py b/addons/account_bank_statement_import/account_bank_statement_import.py index 6a4ef086808..65b1baa27ab 100644 --- a/addons/account_bank_statement_import/account_bank_statement_import.py +++ b/addons/account_bank_statement_import/account_bank_statement_import.py @@ -129,7 +129,7 @@ class AccountBankStatementImport(models.TransientModel): """ Look for a res.currency and account.journal using values extracted from the statement and make sure it's consistent. """ - company_currency = self.env.company_id.currency_id + company_currency = self.env.company.currency_id journal_obj = self.env['account.journal'] currency = None sanitized_account_number = sanitize_account_number(account_number) diff --git a/addons/account_facturx/models/account_invoice.py b/addons/account_facturx/models/account_invoice.py index 911f6a917a2..08676fafb95 100644 --- a/addons/account_facturx/models/account_invoice.py +++ b/addons/account_facturx/models/account_invoice.py @@ -118,7 +118,7 @@ class AccountInvoice(models.Model): if elements[0].attrib.get('currencyID'): currency_str = elements[0].attrib['currencyID'] currency = self.env.ref('base.%s' % currency_str.upper(), raise_if_not_found=False) - if currency != self.env.company_id.currency_id and currency.active: + if currency != self.env.company.currency_id and currency.active: invoice_form.currency_id = currency # Store xml total amount. diff --git a/addons/account_tax_python/models/account_tax.py b/addons/account_tax_python/models/account_tax.py index 0c1f140ee57..883944271ae 100644 --- a/addons/account_tax_python/models/account_tax.py +++ b/addons/account_tax_python/models/account_tax.py @@ -29,7 +29,7 @@ class AccountTaxPython(models.Model): def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None): self.ensure_one() if self.amount_type == 'code': - company = self.env.company_id + company = self.env.company localdict = {'base_amount': base_amount, 'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner, 'company': company} safe_eval(self.python_compute, localdict, mode="exec", nocopy=True) return localdict['result'] @@ -38,7 +38,7 @@ class AccountTaxPython(models.Model): @api.multi def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False): taxes = self.filtered(lambda r: r.amount_type != 'code') - company = self.env.company_id + company = self.env.company for tax in self.filtered(lambda r: r.amount_type == 'code'): localdict = self._context.get('tax_computation_context', {}) localdict.update({'price_unit': price_unit, 'quantity': quantity, 'product': product, 'partner': partner, 'company': company}) diff --git a/addons/account_voucher/models/account_voucher.py b/addons/account_voucher/models/account_voucher.py index 2aadf6fe2fb..7a760249a5d 100644 --- a/addons/account_voucher/models/account_voucher.py +++ b/addons/account_voucher/models/account_voucher.py @@ -16,7 +16,7 @@ class AccountVoucher(models.Model): @api.model def _default_journal(self): voucher_type = self._context.get('voucher_type', 'sale') - company_id = self._context.get('company_id', self.env.company_id.id) + company_id = self._context.get('company_id', self.env.company.id) domain = [ ('type', '=', voucher_type), ('company_id', '=', company_id), @@ -25,7 +25,7 @@ class AccountVoucher(models.Model): @api.model def _default_payment_journal(self): - company_id = self._context.get('company_id', self.env.company_id.id) + company_id = self._context.get('company_id', self.env.company.id) domain = [ ('type', 'in', ('bank', 'cash')), ('company_id', '=', company_id), @@ -96,11 +96,11 @@ class AccountVoucher(models.Model): journal = self.env['account.journal'].browse(self.env.context.get('default_journal_id', False)) if journal.currency_id: return journal.currency_id.id - return self.env.company_id.currency_id.id + return self.env.company.currency_id.id @api.model def _get_company(self): - return self._context.get('company_id', self.env.company_id.id) + return self._context.get('company_id', self.env.company.id) @api.constrains('company_id', 'currency_id') def _check_company_id(self): @@ -274,7 +274,7 @@ class AccountVoucher(models.Model): :return: Tuple build as (remaining amount not allocated on voucher lines, list of account_move_line created in this method) :rtype: tuple(float, list of int) ''' - tax_calculation_rounding_method = self.env.company_id.tax_calculation_rounding_method + tax_calculation_rounding_method = self.env.company.tax_calculation_rounding_method tax_lines_vals = [] for line in self.line_ids: #create one move line per voucher line where amount is not 0.0 diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index 92d038ab732..cddd3c61295 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -93,7 +93,7 @@ class AccountAnalyticAccount(models.Model): if self._context.get('company_ids'): domain.append(('company_id', 'in', self._context['company_ids'])) - user_currency = self.env.company_id.currency_id + user_currency = self.env.company.currency_id credit_groups = analytic_line_obj.read_group( domain=domain + [('amount', '>=', 0.0)], fields=['account_id', 'currency_id', 'amount'], @@ -103,7 +103,7 @@ class AccountAnalyticAccount(models.Model): data_credit = defaultdict(float) for l in credit_groups: data_credit[l['account_id'][0]] += Curr.browse(l['currency_id'][0])._convert( - l['amount'], user_currency, self.env.company_id, fields.Date.today()) + l['amount'], user_currency, self.env.company, fields.Date.today()) debit_groups = analytic_line_obj.read_group( domain=domain + [('amount', '<', 0.0)], @@ -114,7 +114,7 @@ class AccountAnalyticAccount(models.Model): data_debit = defaultdict(float) for l in debit_groups: data_debit[l['account_id'][0]] += Curr.browse(l['currency_id'][0])._convert( - l['amount'], user_currency, self.env.company_id, fields.Date.today()) + l['amount'], user_currency, self.env.company, fields.Date.today()) for account in self: account.debit = abs(data_debit.get(account.id, 0.0)) @@ -129,7 +129,7 @@ class AccountAnalyticAccount(models.Model): line_ids = fields.One2many('account.analytic.line', 'account_id', string="Analytic Lines") - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) # use auto_join to speed up name_search call partner_id = fields.Many2one('res.partner', string='Customer', auto_join=True, tracking=True) @@ -186,7 +186,7 @@ class AccountAnalyticLine(models.Model): partner_id = fields.Many2one('res.partner', string='Partner') user_id = fields.Many2one('res.users', string='User', default=_default_user) tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_line_tag_rel', 'line_id', 'tag_id', string='Tags', copy=True) - company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True, store=True, compute_sudo=True) group_id = fields.Many2one('account.analytic.group', related='account_id.group_id', store=True, readonly=True, compute_sudo=True) diff --git a/addons/base_setup/models/res_config_settings.py b/addons/base_setup/models/res_config_settings.py index 49dccf49bc5..d92aa69047d 100644 --- a/addons/base_setup/models/res_config_settings.py +++ b/addons/base_setup/models/res_config_settings.py @@ -11,7 +11,7 @@ class ResConfigSettings(models.TransientModel): group_multi_company = fields.Boolean("Manage multiple companies", implied_group='base.group_multi_company') group_toggle_company = fields.Boolean("Toggle multiple companies", implied_group='base.group_toggle_company') company_id = fields.Many2one('res.company', string='Company', required=True, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) user_default_rights = fields.Boolean( "Default Access Rights", config_parameter='base_setup.default_user_rights', @@ -68,7 +68,7 @@ class ResConfigSettings(models.TransientModel): 'view_type': 'form', 'view_mode': 'form', 'res_model': 'res.company', - 'res_id': self.env.company_id.id, + 'res_id': self.env.company.id, 'target': 'current', } @api.multi @@ -104,7 +104,7 @@ class ResConfigSettings(models.TransientModel): 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', - 'res_id': self.env.company_id.id, + 'res_id': self.env.company.id, 'res_model': 'res.company', 'views': [(template.id, 'form')], 'view_id': template.id, diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index c25c8641bb8..c747452526f 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -155,7 +155,7 @@ class ResPartner(models.Model): if self.env.context.get('company_id'): company = self.env['res.company'].browse(self.env.context['company_id']) else: - company = self.env.company_id + company = self.env.company if company.vat_check_vies: # force full VIES online check check_func = self.vies_vat_check @@ -182,7 +182,7 @@ class ResPartner(models.Model): if self.env.context.get('company_id'): company = self.env['res.company'].browse(self.env.context['company_id']) else: - company = self.env.company_id + company = self.env.company if company.vat_check_vies: return '\n' + _('The VAT number [%s] for partner [%s] either failed the VIES VAT validation check or did not respect the expected format %s.') % (self.vat, self.name, vat_no) return '\n' + _('The VAT number [%s] for partner [%s] does not seem to be valid. \nNote: the expected format is %s') % (self.vat, self.name, vat_no) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 96a4048d891..27455aefc0f 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -121,7 +121,7 @@ class Lead(models.Model): mobile = fields.Char('Mobile') function = fields.Char('Job Position') title = fields.Many2one('res.partner.title') - company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company_id.id) + company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company.id) meeting_count = fields.Integer('# Meetings', compute='_compute_meeting_count') lost_reason = fields.Many2one('crm.lost.reason', string='Lost Reason', index=True, tracking=True) @@ -1079,7 +1079,7 @@ class Lead(models.Model): result['done']['target'] = self.env.user.target_sales_done result['won']['target'] = self.env.user.target_sales_won - result['currency_id'] = self.env.company_id.currency_id.id + result['currency_id'] = self.env.company.currency_id.id return result diff --git a/addons/crm/tests/test_new_lead_notification.py b/addons/crm/tests/test_new_lead_notification.py index 1b0f4c3a14c..b3b25245869 100644 --- a/addons/crm/tests/test_new_lead_notification.py +++ b/addons/crm/tests/test_new_lead_notification.py @@ -43,7 +43,7 @@ class NewLeadNotification(TestCrmCases): self.assertTrue(lead_user.message_needaction) def test_new_lead_from_email_multicompany(self): - company0 = self.env.company_id + company0 = self.env.company company1 = self.env['res.company'].create({'name': 'new_company'}) self.env.user.write({ diff --git a/addons/crm_iap_lead_website/models/crm_reveal_rule.py b/addons/crm_iap_lead_website/models/crm_reveal_rule.py index d7c6089e821..3300b63f09b 100644 --- a/addons/crm_iap_lead_website/models/crm_reveal_rule.py +++ b/addons/crm_iap_lead_website/models/crm_reveal_rule.py @@ -278,7 +278,7 @@ class CRMRevealRule(models.Model): } def _get_rules_payload(self): - company_country = self.env.company_id.country_id + company_country = self.env.company.country_id rule_payload = {} for rule in self: data = { diff --git a/addons/delivery/tests/test_delivery_cost.py b/addons/delivery/tests/test_delivery_cost.py index a57e617d946..d58fac708d8 100644 --- a/addons/delivery/tests/test_delivery_cost.py +++ b/addons/delivery/tests/test_delivery_cost.py @@ -32,7 +32,7 @@ class TestDeliveryCost(common.TransactionCase): # that the company actually uses USD self.env.cr.execute( "UPDATE res_company SET currency_id = %s WHERE id = %s", - [self.env.ref('base.USD').id, self.env.company_id.id]) + [self.env.ref('base.USD').id, self.env.company.id]) self.pricelist.currency_id = self.env.ref('base.USD').id def test_00_delivery_cost(self): diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py index f7eb085a5b3..8d7f0cbf47d 100644 --- a/addons/digest/models/digest.py +++ b/addons/digest/models/digest.py @@ -33,7 +33,7 @@ class Digest(models.Model): default=lambda self: self.env.ref('digest.digest_mail_template'), required=True) currency_id = fields.Many2one(related="company_id.currency_id", string='Currency', readonly=False) - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id.id) + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company.id) available_fields = fields.Char(compute='_compute_available_fields') is_subscribed = fields.Boolean('Is user subscribed', compute='_compute_is_subscribed') state = fields.Selection([('activated', 'Activated'), ('deactivated', 'Deactivated')], string='Status', readonly=True, default='activated') diff --git a/addons/event/models/event.py b/addons/event/models/event.py index f7ef2f08791..9e141d53e52 100644 --- a/addons/event/models/event.py +++ b/addons/event/models/event.py @@ -103,12 +103,12 @@ class EventEvent(models.Model): readonly=False, states={'done': [('readonly', True)]}) company_id = fields.Many2one( 'res.company', string='Company', change_default=True, - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, required=False, readonly=False, states={'done': [('readonly', True)]}) organizer_id = fields.Many2one( 'res.partner', string='Organizer', tracking=True, - default=lambda self: self.env.company_id.partner_id) + default=lambda self: self.env.company.partner_id) event_type_id = fields.Many2one( 'event.type', string='Category', readonly=False, states={'done': [('readonly', True)]}, @@ -167,7 +167,7 @@ class EventEvent(models.Model): is_online = fields.Boolean('Online Event') address_id = fields.Many2one( 'res.partner', string='Location', - default=lambda self: self.env.company_id.partner_id, + default=lambda self: self.env.company.partner_id, readonly=False, states={'done': [('readonly', True)]}, tracking=True) country_id = fields.Many2one('res.country', 'Country', related='address_id.country_id', store=True, readonly=False) diff --git a/addons/event_sale/models/sale_order.py b/addons/event_sale/models/sale_order.py index 8fc0b64aba3..5a759e8a68d 100644 --- a/addons/event_sale/models/sale_order.py +++ b/addons/event_sale/models/sale_order.py @@ -80,7 +80,7 @@ class SaleOrderLine(models.Model): @api.onchange('event_ticket_id') def _onchange_event_ticket_id(self): - company = self.event_id.company_id or self.env.company_id + company = self.event_id.company_id or self.env.company currency = company.currency_id self.price_unit = currency._convert( self.event_ticket_id.price, self.order_id.currency_id, self.order_id.company_id, self.order_id.date_order or fields.Date.today()) diff --git a/addons/fleet/models/fleet_vehicle.py b/addons/fleet/models/fleet_vehicle.py index 0d4ebd157f4..692e7246b4b 100644 --- a/addons/fleet/models/fleet_vehicle.py +++ b/addons/fleet/models/fleet_vehicle.py @@ -19,7 +19,7 @@ class FleetVehicle(models.Model): name = fields.Char(compute="_compute_vehicle_name", store=True) active = fields.Boolean('Active', default=True, tracking=True) - company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') license_plate = fields.Char(tracking=True, help='License plate number of the vehicle (i = plate number for a car)') diff --git a/addons/fleet/models/fleet_vehicle_cost.py b/addons/fleet/models/fleet_vehicle_cost.py index 453b7a8b1c7..a85ef2c3361 100644 --- a/addons/fleet/models/fleet_vehicle_cost.py +++ b/addons/fleet/models/fleet_vehicle_cost.py @@ -32,7 +32,7 @@ class FleetVehicleCost(models.Model): contract_id = fields.Many2one('fleet.vehicle.log.contract', 'Contract', help='Contract attached to this cost') auto_generated = fields.Boolean('Automatically Generated', readonly=True) description = fields.Char("Cost Description") - company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') def _get_odometer(self): diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index 8cfc9dfeafe..506e34ceb83 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -66,7 +66,7 @@ class GoalDefinition(models.Model): items = [] if goal.monetary: - items.append(self.env.company_id.currency_id.symbol or u'¤') + items.append(self.env.company.currency_id.symbol or u'¤') if goal.suffix: items.append(goal.suffix) diff --git a/addons/hr/models/hr.py b/addons/hr/models/hr.py index 9537910cfff..6f92282e3d2 100644 --- a/addons/hr/models/hr.py +++ b/addons/hr/models/hr.py @@ -47,7 +47,7 @@ class Job(models.Model): description = fields.Text(string='Job Description') requirements = fields.Text('Requirements') department_id = fields.Many2one('hr.department', string='Department') - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) state = fields.Selection([ ('recruit', 'Recruitment in Progress'), ('open', 'Not Recruiting') @@ -382,7 +382,7 @@ class Department(models.Model): name = fields.Char('Department Name', required=True) complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True) active = fields.Boolean('Active', default=True) - company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company) parent_id = fields.Many2one('hr.department', string='Parent Department', index=True) child_ids = fields.One2many('hr.department', 'parent_id', string='Child Departments') manager_id = fields.Many2one('hr.employee', string='Manager', tracking=True) diff --git a/addons/hr_attendance_presence/models/hr_employee.py b/addons/hr_attendance_presence/models/hr_employee.py index af259d7fc4f..3f99535da87 100644 --- a/addons/hr_attendance_presence/models/hr_employee.py +++ b/addons/hr_attendance_presence/models/hr_employee.py @@ -16,7 +16,7 @@ class Employee(models.Model): action = super(Employee, self)._action_open_presence_view() if self.env['ir.config_parameter'].sudo().get_param('hr_presence.hr_presence_control_attendance'): - company = self.env.company_id + company = self.env.company employees = self.env['hr.employee'].search([ ('department_id.company_id', '=', company.id), ('user_id', '!=', False), diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index 3ca0a37c304..1fbecc1b114 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -63,7 +63,7 @@ class Contract(models.Model): help="End date of the trial period (if there is one).") resource_calendar_id = fields.Many2one( 'resource.calendar', 'Working Schedule', - default=lambda self: self.env.company_id.resource_calendar_id.id) + default=lambda self: self.env.company.resource_calendar_id.id) wage = fields.Monetary('Wage', digits=(16, 2), required=True, tracking=True, help="Employee's monthly gross wage.") advantages = fields.Text('Advantages') notes = fields.Text('Notes') @@ -76,7 +76,7 @@ class Contract(models.Model): ('cancel', 'Cancelled') ], string='Status', group_expand='_expand_states', tracking=True, help='Status of the contract', default='draft') - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) currency_id = fields.Many2one(string="Currency", related='company_id.currency_id', readonly=True) permit_no = fields.Char('Work Permit No', related="employee_id.permit_no", readonly=False) visa_no = fields.Char('Visa No', related="employee_id.visa_no", readonly=False) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 233f3d242bd..7c028f4d47e 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -56,8 +56,8 @@ class HrExpense(models.Model): untaxed_amount = fields.Float("Subtotal", store=True, compute='_compute_amount', digits=dp.get_precision('Account')) total_amount = fields.Monetary("Total", compute='_compute_amount', store=True, currency_field='currency_id', digits=dp.get_precision('Account')) total_amount_company = fields.Monetary("Total (Company Currency)", compute='_compute_total_amount_company', store=True, currency_field='company_currency_id', digits=dp.get_precision('Account')) - company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company_id) - currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company_id.currency_id) + company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company) + currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company.currency_id) company_currency_id = fields.Many2one('res.currency', string="Report Company Currency", related='sheet_id.currency_id', store=True, readonly=False) analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', states={'post': [('readonly', True)], 'done': [('readonly', True)]}, oldname='analytic_account') analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', states={'post': [('readonly', True)], 'done': [('readonly', True)]}) @@ -224,7 +224,7 @@ class HrExpense(models.Model): journal = expense.sheet_id.bank_journal_id if expense.payment_mode == 'company_account' else expense.sheet_id.journal_id move = self.env['account.move'].create({ 'journal_id': journal.id, - 'company_id': self.env.company_id.id, + 'company_id': self.env.company.id, 'date': account_date, 'ref': expense.sheet_id.name, # force the name to the default value, to avoid an eventual 'default_name' in the context @@ -595,8 +595,8 @@ class HrExpenseSheet(models.Model): payment_mode = fields.Selection(related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Paid By") user_id = fields.Many2one('res.users', 'Manager', readonly=True, copy=False, states={'draft': [('readonly', False)]}, tracking=True, oldname='responsible_id') total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True, digits=dp.get_precision('Account')) - company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company_id) - currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company_id.currency_id) + company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company) + currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company.currency_id) attachment_number = fields.Integer(compute='_compute_attachment_number', string='Number of Attachments') journal_id = fields.Many2one('account.journal', string='Expense Journal', states={'done': [('readonly', True)], 'post': [('readonly', True)]}, default=_default_journal_id, help="The journal used when the expense is done.") bank_journal_id = fields.Many2one('account.journal', string='Bank Journal', states={'done': [('readonly', True)], 'post': [('readonly', True)]}, default=_default_bank_journal_id, help="The payment method used when the expense is paid by the company.") @@ -697,7 +697,7 @@ class HrExpenseSheet(models.Model): raise UserError(_("Expenses must have an expense journal specified to generate accounting entries.")) expense_line_ids = self.mapped('expense_line_ids')\ - .filtered(lambda r: not float_is_zero(r.total_amount, precision_rounding=(r.currency_id or self.env.company_id.currency_id).rounding)) + .filtered(lambda r: not float_is_zero(r.total_amount, precision_rounding=(r.currency_id or self.env.company.currency_id).rounding)) res = expense_line_ids.action_move_create() if not self.accounting_date: diff --git a/addons/hr_expense/tests/test_expenses.py b/addons/hr_expense/tests/test_expenses.py index 5ab7abe3d67..ab31f29c804 100644 --- a/addons/hr_expense/tests/test_expenses.py +++ b/addons/hr_expense/tests/test_expenses.py @@ -83,11 +83,11 @@ class TestAccountEntry(TestExpenseCommon): multi-currency. And taxes. """ # Clean-up the rates - self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.env.ref('base.USD').id, self.env.company_id.id]) + self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.env.ref('base.USD').id, self.env.company.id]) self.env['res.currency.rate'].search([]).unlink() self.env['res.currency.rate'].create({ 'currency_id': self.env.ref('base.EUR').id, - 'company_id': self.env.company_id.id, + 'company_id': self.env.company.id, 'rate': 2.0, 'name': '2010-01-01', }) @@ -142,7 +142,7 @@ class TestAccountEntry(TestExpenseCommon): self.assertEquals(self.analytic_account.line_ids, expense.account_move_id.mapped('line_ids.analytic_line_ids')) self.assertEquals(len(self.analytic_account.line_ids), 1, "Analytic Account should have only one line") self.assertAlmostEquals(self.analytic_account.line_ids[0].amount, -318.18, "Amount on the only AAL is wrong") - self.assertAlmostEquals(self.analytic_account.line_ids[0].currency_id, self.env.company_id.currency_id, "Currency on the only AAL is wrong") + self.assertAlmostEquals(self.analytic_account.line_ids[0].currency_id, self.env.company.currency_id, "Currency on the only AAL is wrong") self.assertEquals(self.analytic_account.line_ids[0].product_id, self.product_expense, "Product of AAL should be the one from the expense") def test_expense_from_email(self): diff --git a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py index 2cacf083f74..9a98f40dc59 100644 --- a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py +++ b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py @@ -23,7 +23,7 @@ class HrExpenseSheetRegisterPaymentWizard(models.TransientModel): company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', readonly=True, required=True) payment_method_id = fields.Many2one('account.payment.method', string='Payment Type', required=True) amount = fields.Monetary(string='Payment Amount', required=True) - currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self.env.company_id.currency_id) + currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self.env.company.currency_id) payment_date = fields.Date(string='Payment Date', default=fields.Date.context_today, required=True) communication = fields.Char(string='Memo') hide_payment_method = fields.Boolean(compute='_compute_hide_payment_method', diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index f52670a1c9c..061b76dbe1b 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -277,7 +277,7 @@ class HolidaysRequest(models.Model): self.date_to = False return - domain = [('calendar_id', '=', self.employee_id.resource_calendar_id.id or self.env.company_id.resource_calendar_id.id)] + domain = [('calendar_id', '=', self.employee_id.resource_calendar_id.id or self.env.company.resource_calendar_id.id)] attendances = self.env['resource.calendar.attendance'].search(domain, order='dayofweek, day_period DESC') # find first attendance coming after first_day @@ -342,7 +342,7 @@ class HolidaysRequest(models.Model): elif self.holiday_type == 'company': self.employee_id = False if not self.mode_company_id: - self.mode_company_id = self.env.company_id.id + self.mode_company_id = self.env.company.id self.category_id = False elif self.holiday_type == 'department': self.employee_id = False @@ -378,7 +378,7 @@ class HolidaysRequest(models.Model): @api.depends('number_of_days') def _compute_number_of_hours_display(self): for holiday in self: - calendar = holiday.employee_id.resource_calendar_id or self.env.company_id.resource_calendar_id + calendar = holiday.employee_id.resource_calendar_id or self.env.company.resource_calendar_id if holiday.date_from and holiday.date_to: number_of_hours = calendar.get_work_hours_count(holiday.date_from, holiday.date_to) holiday.number_of_hours_display = number_of_hours or (holiday.number_of_days * HOURS_PER_DAY) @@ -440,12 +440,12 @@ class HolidaysRequest(models.Model): employee = self.env['hr.employee'].browse(employee_id) return employee._get_work_days_data(date_from, date_to)['days'] - today_hours = self.env.company_id.resource_calendar_id.get_work_hours_count( + today_hours = self.env.company.resource_calendar_id.get_work_hours_count( datetime.combine(date_from.date(), time.min), datetime.combine(date_from.date(), time.max), False) - return self.env.company_id.resource_calendar_id.get_work_hours_count(date_from, date_to) / (today_hours or HOURS_PER_DAY) + return self.env.company.resource_calendar_id.get_work_hours_count(date_from, date_to) / (today_hours or HOURS_PER_DAY) #################################################### # ORM Overrides methods @@ -611,7 +611,7 @@ class HolidaysRequest(models.Model): @api.multi def _prepare_holidays_meeting_values(self): self.ensure_one() - calendar = self.employee_id.resource_calendar_id or self.env.company_id.resource_calendar_id + calendar = self.employee_id.resource_calendar_id or self.env.company.resource_calendar_id meeting_values = { 'name': self.display_name, 'categ_ids': [(6, 0, [ diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 5b63c146363..1fb529ff390 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -64,7 +64,7 @@ class HolidaysType(models.Model): compute='_compute_group_days_allocation', string='Days Allocated') group_days_leave = fields.Float( compute='_compute_group_days_leave', string='Group Time Off') - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) responsible_id = fields.Many2one('res.users', 'Responsible', domain=lambda self: [('groups_id', 'in', self.env.ref('hr_holidays.group_hr_holidays_user').id)], help="This user will be responsible for approving this type of times off" "This is only used when validation is 'hr' or 'both'",) @@ -220,7 +220,7 @@ class HolidaysType(models.Model): elif 'default_employee_id' in self._context: employee_id = self._context['default_employee_id'] else: - employee_id = self.env['hr.employee'].search([('user_id', '=', self.env.user.id), ('company_id', '=', self.env.company_id.id)], limit=1).id + employee_id = self.env['hr.employee'].search([('user_id', '=', self.env.user.id), ('company_id', '=', self.env.company.id)], limit=1).id return employee_id @api.multi diff --git a/addons/hr_org_chart/controllers/hr_org_chart.py b/addons/hr_org_chart/controllers/hr_org_chart.py index a82d9002d33..4a8fb029dda 100644 --- a/addons/hr_org_chart/controllers/hr_org_chart.py +++ b/addons/hr_org_chart/controllers/hr_org_chart.py @@ -17,7 +17,7 @@ class HrOrgChartController(http.Controller): if ('context' in kw and 'allowed_company_ids' in kw['context']): cids = kw['context']['allowed_company_ids'] else: - cids = [request.env.company_id.id] + cids = [request.env.company.id] Employee = request.env['hr.employee'].with_context(allowed_company_ids=cids) # check and raise diff --git a/addons/hr_presence/models/hr_employee.py b/addons/hr_presence/models/hr_employee.py index 3c27bf4874c..9e6815f1461 100644 --- a/addons/hr_presence/models/hr_employee.py +++ b/addons/hr_presence/models/hr_employee.py @@ -28,7 +28,7 @@ class ResCompany(models.Model): @api.model def _check_presence(self): - company = self.env.company_id + company = self.env.company if not company.hr_presence_last_compute_date or \ company.hr_presence_last_compute_date.day != Datetime.now().day: self.env['hr.employee'].search([ diff --git a/addons/hr_recruitment/models/hr_job.py b/addons/hr_recruitment/models/hr_job.py index 50f63374447..280a096b5df 100644 --- a/addons/hr_recruitment/models/hr_job.py +++ b/addons/hr_recruitment/models/hr_job.py @@ -10,7 +10,7 @@ class Job(models.Model): @api.model def _default_address_id(self): - return self.env.company_id.partner_id + return self.env.company.partner_id def _get_default_favorite_user_ids(self): return [(6, 0, [self.env.uid])] diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index 88185cace9f..7bd1021769a 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -110,7 +110,7 @@ class Applicant(models.Model): department = self.env['hr.department'].browse(self._context['default_department_id']) company_id = department.company_id.id if not company_id: - company_id = self.env.company_id + company_id = self.env.company return company_id name = fields.Char("Subject / Application Name", required=True) diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index c7f31dee0bb..ce2abd5f871 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -90,7 +90,7 @@ class AccountAnalyticLine(models.Model): @api.model def _apply_timesheet_label(self, view_arch): doc = etree.XML(view_arch) - encoding_uom = self.env.company_id.timesheet_encode_uom_id + encoding_uom = self.env.company.timesheet_encode_uom_id # Here, we select only the unit_amount field having no string set to give priority to # custom inheretied view stored in database. Even if normally, no xpath can be done on # 'string' attribute. @@ -159,7 +159,7 @@ class AccountAnalyticLine(models.Model): cost = timesheet.employee_id.timesheet_cost or 0.0 amount = -timesheet.unit_amount * cost amount_converted = timesheet.employee_id.currency_id._convert( - amount, timesheet.account_id.currency_id, self.env.company_id, timesheet.date) + amount, timesheet.account_id.currency_id, self.env.company, timesheet.date) result[timesheet.id].update({ 'amount': amount_converted, }) diff --git a/addons/hr_timesheet/models/ir_http.py b/addons/hr_timesheet/models/ir_http.py index d20ad2f9d7a..17e7be32084 100644 --- a/addons/hr_timesheet/models/ir_http.py +++ b/addons/hr_timesheet/models/ir_http.py @@ -13,7 +13,7 @@ class Http(models.AbstractModel): """ result = super(Http, self).session_info() - company = self.env.company_id + company = self.env.company encoding_uom = company.timesheet_encode_uom_id result['timesheet_uom'] = encoding_uom.read(['name', 'rounding', 'timesheet_widget'])[0] diff --git a/addons/iap/models/iap.py b/addons/iap/models/iap.py index 122aab66b35..998eb6850b2 100644 --- a/addons/iap/models/iap.py +++ b/addons/iap/models/iap.py @@ -158,11 +158,11 @@ class IapAccount(models.Model): service_name = fields.Char() account_token = fields.Char(default=lambda s: uuid.uuid4().hex) - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) @api.model def get(self, service_name, force_create=True): - account = self.search([('service_name', '=', service_name), ('company_id', 'in', [self.env.company_id.id, False])]) + account = self.search([('service_name', '=', service_name), ('company_id', 'in', [self.env.company.id, False])]) if not account and force_create: account = self.create({'service_name': service_name}) # Since the account did not exist yet, we will encounter a NoCreditError, diff --git a/addons/l10n_de/models/chart_template.py b/addons/l10n_de/models/chart_template.py index fb830340b33..22c1b18af74 100644 --- a/addons/l10n_de/models/chart_template.py +++ b/addons/l10n_de/models/chart_template.py @@ -17,7 +17,7 @@ class AccountChartTemplate(models.Model): # Write paperformat and report template used on company def load_for_current_company(self, sale_tax_rate, purchase_tax_rate): res = super(AccountChartTemplate, self).load_for_current_company(sale_tax_rate, purchase_tax_rate) - company = self.env.company_id + company = self.env.company if company.country_id.code == 'DE': company.write({'external_report_layout_id': self.env.ref('l10n_de.external_layout_din5008').id, 'paperformat_id': self.env.ref('l10n_de.paperformat_euro_din').id}) diff --git a/addons/l10n_do/models/chart_template.py b/addons/l10n_do/models/chart_template.py index 892cb8582e5..f21dde62ddf 100644 --- a/addons/l10n_do/models/chart_template.py +++ b/addons/l10n_do/models/chart_template.py @@ -9,7 +9,7 @@ class AccountChartTemplate(models.Model): @api.model def _get_default_bank_journals_data(self): - if self.env.company_id.country_id and self.env.company_id.country_id.code.upper() == 'DO': + if self.env.company.country_id and self.env.company.country_id.code.upper() == 'DO': return [ {'acc_name': _('Cash'), 'account_type': 'cash'}, {'acc_name': _('Caja Chica'), 'account_type': 'cash'}, diff --git a/addons/l10n_eu_service/wizard/wizard.py b/addons/l10n_eu_service/wizard/wizard.py index 2e90c94ecea..abcdd56316e 100644 --- a/addons/l10n_eu_service/wizard/wizard.py +++ b/addons/l10n_eu_service/wizard/wizard.py @@ -18,7 +18,7 @@ class l10n_eu_service(models.TransientModel): return eu_group def _get_default_company_id(self): - return self.env.company_id.id + return self.env.company.id def _default_fiscal_position_id(self): user = self.env.user diff --git a/addons/l10n_fr_certification/data/account_move.xml b/addons/l10n_fr_certification/data/account_move.xml index cb72a999561..a551cb7f080 100644 --- a/addons/l10n_fr_certification/data/account_move.xml +++ b/addons/l10n_fr_certification/data/account_move.xml @@ -5,7 +5,7 @@ <field name="type">ir.actions.server</field> <field name="state">code</field> <field name="code"> - action = env['account.move']._check_hash_integrity(env.company_id.id) + action = env['account.move']._check_hash_integrity(env.company.id) </field> </record> diff --git a/addons/l10n_fr_certification/models/account.py b/addons/l10n_fr_certification/models/account.py index a85eaebfebc..91a6e0df1c3 100644 --- a/addons/l10n_fr_certification/models/account.py +++ b/addons/l10n_fr_certification/models/account.py @@ -117,7 +117,7 @@ class AccountMove(models.Model): order="l10n_fr_secure_sequence_number ASC") if not moves: - raise UserError(_('There isn\'t any journal entry flagged for data inalterability yet for the company %s. This mechanism only runs for journal entries generated after the installation of the module France - Certification CGI 286 I-3 bis.') % self.env.company_id.name) + raise UserError(_('There isn\'t any journal entry flagged for data inalterability yet for the company %s. This mechanism only runs for journal entries generated after the installation of the module France - Certification CGI 286 I-3 bis.') % self.env.company.name) previous_hash = u'' start_move_info = [] for move in moves: diff --git a/addons/l10n_fr_fec/wizard/account_fr_fec.py b/addons/l10n_fr_fec/wizard/account_fr_fec.py index 0c0ec49558e..6d8b0bc62f0 100644 --- a/addons/l10n_fr_fec/wizard/account_fr_fec.py +++ b/addons/l10n_fr_fec/wizard/account_fr_fec.py @@ -65,7 +65,7 @@ class AccountFrFec(models.TransientModel): sql_query += ''' AND am.state = 'posted' ''' - company = self.env.company_id + company = self.env.company formatted_date_from = fields.Date.to_string(self.date_from).replace('-', '') date_from = self.date_from formatted_date_year = date_from.year @@ -108,7 +108,7 @@ class AccountFrFec(models.TransientModel): # 2) CSV files are easier to read/use for a regular accountant. # So it will be easier for the accountant to check the file before # sending it to the fiscal administration - company = self.env.company_id + company = self.env.company company_legal_data = self._get_company_legal_data(company) header = [ diff --git a/addons/l10n_fr_pos_cert/data/pos_inalterability.xml b/addons/l10n_fr_pos_cert/data/pos_inalterability.xml index 1026c9b90d2..39d1f59c699 100644 --- a/addons/l10n_fr_pos_cert/data/pos_inalterability.xml +++ b/addons/l10n_fr_pos_cert/data/pos_inalterability.xml @@ -10,7 +10,7 @@ <field name="type">ir.actions.server</field> <field name="state">code</field> <field name="code"> -action = env['pos.order']._check_hash_integrity(env.company_id.id) +action = env['pos.order']._check_hash_integrity(env.company.id) </field> </record> diff --git a/addons/l10n_fr_pos_cert/models/pos.py b/addons/l10n_fr_pos_cert/models/pos.py index 89d027b0123..6a11fdfac6c 100644 --- a/addons/l10n_fr_pos_cert/models/pos.py +++ b/addons/l10n_fr_pos_cert/models/pos.py @@ -154,7 +154,7 @@ class pos_order(models.Model): order="l10n_fr_secure_sequence_number ASC") if not orders: - raise UserError(_('There isn\'t any order flagged for data inalterability yet for the company %s. This mechanism only runs for point of sale orders generated after the installation of the module France - Certification CGI 286 I-3 bis. - POS') % self.env.company_id.name) + raise UserError(_('There isn\'t any order flagged for data inalterability yet for the company %s. This mechanism only runs for point of sale orders generated after the installation of the module France - Certification CGI 286 I-3 bis. - POS') % self.env.company.name) previous_hash = u'' start_order_info = [] for order in orders: diff --git a/addons/l10n_generic_coa/data/account_bank_statement_demo.xml b/addons/l10n_generic_coa/data/account_bank_statement_demo.xml index 8a34bad5be1..781c598961d 100644 --- a/addons/l10n_generic_coa/data/account_bank_statement_demo.xml +++ b/addons/l10n_generic_coa/data/account_bank_statement_demo.xml @@ -4,7 +4,7 @@ <record id="demo_bank_statement_1" model="account.bank.statement"> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="name" eval="'BNK/%s/0001' % time.strftime('%Y')"/> <field name="balance_end_real">8998.2</field> @@ -18,7 +18,7 @@ <field name="name" eval="'INV/%s/0002 and INV/%s/0003' % (time.strftime('%Y'), time.strftime('%Y'))"/> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">1275.0</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="partner_id" ref="base.res_partner_2"/> @@ -31,7 +31,7 @@ <field name="name">Bank fees</field> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">-32.58</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> </record> @@ -43,7 +43,7 @@ <field name="name">Prepayment</field> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">650.0</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="partner_id" ref="base.res_partner_12"/> @@ -56,7 +56,7 @@ <field name="name" eval="'First 2000 $ of invoice %s/0001' % time.strftime('%Y')"/> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">2000.0</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="partner_id" ref="base.res_partner_12"/> @@ -69,7 +69,7 @@ <field name="name">Last Year Interests</field> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">102.78</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> </record> @@ -81,7 +81,7 @@ <field name="name" eval="'INV/'+time.strftime('%Y')+'/0002'"/> <field name="journal_id" model="account.journal" search="[ ('type', '=', 'bank'), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="amount">750.0</field> <field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="partner_id" ref="base.res_partner_2"/> diff --git a/addons/l10n_generic_coa/data/account_invoice_demo.xml b/addons/l10n_generic_coa/data/account_invoice_demo.xml index 47cefa73854..55828f6870f 100644 --- a/addons/l10n_generic_coa/data/account_invoice_demo.xml +++ b/addons/l10n_generic_coa/data/account_invoice_demo.xml @@ -168,7 +168,7 @@ <field name="account_id" model="account.account" search="['|', ('tag_ids', '=', ref('account.demo_ceo_wages_account')), ('user_type_id', '=', ref('account.data_account_type_expenses')), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> </record> <function model="account.invoice" name="action_invoice_open"> <value eval="[ref('demo_invoice_january_wages')]"/> @@ -189,12 +189,12 @@ <field name="account_id" model="account.account" search="['|', ('tag_ids', '=', ref('account.demo_office_furniture_account')), ('user_type_id', '=', ref('account.data_account_type_expenses')), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> <field name="invoice_line_tax_ids" model="account.tax" eval="[(6, 0, obj().search([ ('type_tax_use', '=', 'purchase'), ('amount', '>', 0), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> @@ -209,7 +209,7 @@ <field name="account_id" model="account.account" search="[ ('user_type_id', '=', ref('account.data_account_type_revenue')), ('tag_ids', 'in', [ref('account.account_tag_financing')]), - ('company_id', '=', obj().env.company_id.id)]"/> + ('company_id', '=', obj().env.company.id)]"/> </record> <function model="account.bank.statement.line" name="fast_counterpart_creation"> diff --git a/addons/l10n_in/data/account_invoice_demo.xml b/addons/l10n_in/data/account_invoice_demo.xml index 2e1e24eb755..f66e55f6d30 100644 --- a/addons/l10n_in/data/account_invoice_demo.xml +++ b/addons/l10n_in/data/account_invoice_demo.xml @@ -24,7 +24,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 28), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_b2b_line_2" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_9').partner_ref"/> @@ -39,7 +39,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_b2b_line_3" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_10').partner_ref"/> @@ -52,7 +52,7 @@ <field name="invoice_line_tax_ids" model="account.tax" eval="[(6, 0, obj().search([ ('type_tax_use', '=', 'sale'), - ('company_id', '=', obj().env.company_id.id), + ('company_id', '=', obj().env.company.id), '|', '&', ('amount', '=', 18), @@ -94,7 +94,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_b2cs_line_2" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_20').partner_ref"/> @@ -109,7 +109,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_b2cs_line_3" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_22').partner_ref"/> @@ -124,7 +124,7 @@ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), ('amount','=', 5), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_b2cs_line_4" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_24').partner_ref"/> @@ -139,7 +139,7 @@ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), ('amount','=', 5), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> @@ -172,7 +172,7 @@ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.igst_group').id), ('amount','=', 18), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> @@ -195,7 +195,7 @@ eval="obj().search([ ('type', '=', 'sale'), ('l10n_in_import_export', '=', True), - ('company_id', '=', obj().env.company_id.id)], limit=1).id + ('company_id', '=', obj().env.company.id)], limit=1).id or obj().search([('type', '=', 'sale')], limit=1).id"/> <field name="l10n_in_shipping_bill_number">999704</field> <field name="l10n_in_shipping_bill_date" eval="time.strftime('%Y-%m')+'-02'"/> @@ -215,7 +215,7 @@ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.igst_group').id), ('amount','=', 18), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> @@ -247,7 +247,7 @@ eval="[(6, 0, obj().search([ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.exempt_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_nill_line_2" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_5').partner_ref"/> @@ -261,7 +261,7 @@ eval="[(6, 0, obj().search([ ('type_tax_use', '=', 'sale'), ('tax_group_id', '=', obj().env.ref('l10n_in.nil_rated_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> @@ -298,7 +298,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 28), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_cdnr_line_2" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_9').partner_ref"/> @@ -313,7 +313,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <record id="demo_invoice_cdnr_line_3" model="account.invoice.line"> <field name="name" model="account.invoice.line" eval="obj().env.ref('product.product_product_10').partner_ref"/> @@ -326,7 +326,7 @@ <field name="invoice_line_tax_ids" model="account.tax" eval="[(6, 0, obj().search([ ('type_tax_use', '=', 'sale'), - ('company_id', '=', obj().env.company_id.id), + ('company_id', '=', obj().env.company.id), '|', '&', ('amount', '=', 18), @@ -369,7 +369,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> @@ -403,7 +403,7 @@ ('type_tax_use', '=', 'sale'), ('amount','=', 18), ('tax_group_id', '=', obj().env.ref('l10n_in.gst_group').id), - ('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/> + ('company_id', '=', obj().env.company.id)], limit=1).ids)]"/> </record> <function model="account.invoice" name="_onchange_invoice_line_ids"> diff --git a/addons/l10n_in/data/account_payment_demo.xml b/addons/l10n_in/data/account_payment_demo.xml index bc2f31b8bb7..c8ef4088a64 100644 --- a/addons/l10n_in/data/account_payment_demo.xml +++ b/addons/l10n_in/data/account_payment_demo.xml @@ -11,11 +11,11 @@ <field name="journal_id" model="account.journal" eval="obj().search([ ('type', '=', 'cash'), - ('company_id', '=', obj().env.company_id.id)], limit=1).id"/> + ('company_id', '=', obj().env.company.id)], limit=1).id"/> <field name="payment_method_id" model="account.journal" eval="obj().search([ ('type', '=', 'cash'), - ('company_id', '=', obj().env.company_id.id)], limit=1).inbound_payment_method_ids[0].id"/> + ('company_id', '=', obj().env.company.id)], limit=1).inbound_payment_method_ids[0].id"/> </record> <function model="account.payment" name="post"> diff --git a/addons/l10n_it_edi/models/account_invoice.py b/addons/l10n_it_edi/models/account_invoice.py index 6b027bc6354..b1a7072eb22 100644 --- a/addons/l10n_it_edi/models/account_invoice.py +++ b/addons/l10n_it_edi/models/account_invoice.py @@ -271,16 +271,16 @@ class AccountInvoice(models.Model): message = self.env['mail.message'].create({ 'subject': _('Sending file: %s') % (self.l10n_it_einvoice_id.name), - 'body': _('Sending file: %s to ES: %s') % (self.l10n_it_einvoice_id.name, self.env.company_id.l10n_it_address_recipient_fatturapa), + 'body': _('Sending file: %s to ES: %s') % (self.l10n_it_einvoice_id.name, self.env.company.l10n_it_address_recipient_fatturapa), 'author_id': self.env.user.partner_id.id, - 'email_from': self.env.company_id.l10n_it_address_send_fatturapa, - 'mail_server_id': self.env.company_id.l10n_it_mail_pec_server_id.id, + 'email_from': self.env.company.l10n_it_address_send_fatturapa, + 'mail_server_id': self.env.company.l10n_it_mail_pec_server_id.id, 'attachment_ids': [(6, 0, self.l10n_it_einvoice_id.ids)], }) mail_fattura = self.env['mail.mail'].create({ 'mail_message_id': message.id, - 'email_to': self.env.company_id.l10n_it_address_recipient_fatturapa, + 'email_to': self.env.company.l10n_it_address_recipient_fatturapa, }) try: mail_fattura.send(raise_exception=True) @@ -332,15 +332,15 @@ class AccountInvoice(models.Model): if company: self_ctx = self_ctx.with_context(company_id=company.id) else: - company = self.env.company_id + company = self.env.company if elements: _logger.info(_('Company not found with codice fiscale: %s. The company\'s user is set by default.') % elements[0].text) else: _logger.info(_('Company not found. The company\'s user is set by default.')) if not self.env.user._is_superuser(): - if self.env.company_id != company: - raise UserError(_("You can only import invoice concern your current company: %s") % self.env.company_id.display_name) + if self.env.company != company: + raise UserError(_("You can only import invoice concern your current company: %s") % self.env.company.display_name) journal_id = self_ctx._default_journal().id self_ctx = self_ctx.with_context(journal_id=journal_id) @@ -395,7 +395,7 @@ class AccountInvoice(models.Model): if elements: currency_str = elements[0].text currency = self.env.ref('base.%s' % currency_str.upper(), raise_if_not_found=False) - if currency != self.env.company_id.currency_id and currency.active: + if currency != self.env.company.currency_id and currency.active: invoice_form.currency_id = currency # Date. <2.1.1.3> diff --git a/addons/l10n_nl/models/account_chart_template.py b/addons/l10n_nl/models/account_chart_template.py index d7a4a2ae75d..17c494c0481 100644 --- a/addons/l10n_nl/models/account_chart_template.py +++ b/addons/l10n_nl/models/account_chart_template.py @@ -9,8 +9,8 @@ class AccountChartTemplate(models.Model): def load_for_current_company(self, sale_tax_rate, purchase_tax_rate): # Add tag to 999999 account res = super(AccountChartTemplate, self).load_for_current_company(sale_tax_rate, purchase_tax_rate) - if self.env.company_id.country_id.code == 'NL': - account = self.env['account.account'].search([('code', '=', '999999'), ('company_id', '=', self.env.company_id.id)]) + if self.env.company.country_id.code == 'NL': + account = self.env['account.account'].search([('code', '=', '999999'), ('company_id', '=', self.env.company.id)]) if account: account.tag_ids = [(4, self.env.ref('l10n_nl.account_tag_12').id)] return res diff --git a/addons/lunch/models/lunch_cashmove.py b/addons/lunch/models/lunch_cashmove.py index d04d3b79d32..bfac0777959 100644 --- a/addons/lunch/models/lunch_cashmove.py +++ b/addons/lunch/models/lunch_cashmove.py @@ -11,7 +11,7 @@ class LunchCashMove(models.Model): _description = 'Lunch Cashmove' _order = 'date desc' - currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company_id) + currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company) user_id = fields.Many2one('res.users', 'User', default=lambda self: self.env.uid) date = fields.Date('Date', required=True, default=fields.Date.context_today) diff --git a/addons/lunch/models/lunch_order.py b/addons/lunch/models/lunch_order.py index 911b7315c46..52e4917e58d 100644 --- a/addons/lunch/models/lunch_order.py +++ b/addons/lunch/models/lunch_order.py @@ -36,7 +36,7 @@ class LunchOrder(models.Model): ('confirmed', 'Received'), ('cancelled', 'Cancelled')], 'Status', readonly=True, index=True, default='new') - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id.id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company.id) currency_id = fields.Many2one('res.currency', related='company_id.currency_id', readonly=True, store=True) quantity = fields.Float('Quantity', required=True, default=1) diff --git a/addons/lunch/models/lunch_product.py b/addons/lunch/models/lunch_product.py index ea3306c3df4..701d7885de4 100644 --- a/addons/lunch/models/lunch_product.py +++ b/addons/lunch/models/lunch_product.py @@ -13,7 +13,7 @@ class LunchProductCategory(models.Model): _description = 'Lunch Product Category' name = fields.Char('Product Category', required=True) - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') topping_label_1 = fields.Char('Topping 1 Label', required=True, default='Supplements') topping_label_2 = fields.Char('Topping 2 Label', required=True, default='Beverages') @@ -67,14 +67,14 @@ class LunchTopping(models.Model): _description = 'Lunch Toppings' name = fields.Char('Name', required=True) - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') price = fields.Float('Price', digits=dp.get_precision('Account'), required=True) category_id = fields.Many2one('lunch.product.category') topping_category = fields.Integer('Topping Category', help="This field is a technical field", required=True, default=1) def name_get(self): - currency_id = self.env.company_id.currency_id + currency_id = self.env.company.currency_id res = dict(super(LunchTopping, self).name_get()) for topping in self: price = formatLang(self.env, topping.price, currency_obj=currency_id) @@ -95,7 +95,7 @@ class LunchProduct(models.Model): supplier_id = fields.Many2one('lunch.supplier', 'Vendor', required=True) active = fields.Boolean(default=True) - company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') # image: all image fields are base64 encoded and PIL-supported diff --git a/addons/lunch/wizard/lunch_line_wizard.py b/addons/lunch/wizard/lunch_line_wizard.py index 989d3a0acc8..e933c1e6008 100644 --- a/addons/lunch/wizard/lunch_line_wizard.py +++ b/addons/lunch/wizard/lunch_line_wizard.py @@ -21,7 +21,7 @@ class LunchOrderWizard(models.TransientModel): order="date desc, id desc", limit=1) return last_time_ordered - currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company_id.currency_id) + currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company.currency_id) product_id = fields.Many2one('lunch.product', string='Product ID') product_description = fields.Text('Description', related='product_id.description') diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index f59f26e0a66..c9a54701ca7 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -1225,7 +1225,7 @@ class Message(models.Model): if self.env.user.partner_id.email: email_from = formataddr((self.env.user.partner_id.name, self.env.user.partner_id.email)) else: - email_from = self.env.company_id.catchall + email_from = self.env.company.catchall body_html = tools.append_content_to_html('<div>%s</div>' % tools.ustr(comment), msg.body) vals = { diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 258bc957252..0ced62009dd 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -539,7 +539,7 @@ class MailTemplate(models.Model): template_ctx = { 'message': self.env['mail.message'].sudo().new(dict(body=values['body_html'], record_name=record.display_name)), 'model_description': self.env['ir.model']._get(record._name).display_name, - 'company': 'company_id' in record and record['company_id'] or self.env.company_id, + 'company': 'company_id' in record and record['company_id'] or self.env.company, } body = template.render(template_ctx, engine='ir.qweb', minimal_qcontext=True) values['body_html'] = self.env['mail.thread']._replace_local_links(body) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index af5929429dc..b55f5cc0937 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -866,7 +866,7 @@ class MailThread(models.AbstractModel): result_email.update(dict((rid, '%s@%s' % (catchall, alias_domain)) for rid in left_ids)) # compute name of reply-to - TDE tocheck: quotes and stuff like that - company_name = company.name if company else self.env.company_id.name + company_name = company.name if company else self.env.company.name for res_id in result_email.keys(): name = '%s%s%s' % (company_name, ' ' if doc_names.get(res_id) else '', doc_names.get(res_id, '')) result[res_id] = formataddr((name, result_email[res_id])) @@ -1252,7 +1252,7 @@ class MailThread(models.AbstractModel): body = self.env.ref('mail.mail_bounce_catchall').render({ 'message': message, }, engine='ir.qweb') - self._routing_create_bounce_email(email_from, body, message, reply_to=self.env.company_id.email) + self._routing_create_bounce_email(email_from, body, message, reply_to=self.env.company.email) return [] dest_aliases = Alias.search([('alias_name', 'in', rcpt_tos_localparts)]) diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index 4961b367fbf..3677527e17a 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -32,7 +32,7 @@ class MaintenanceEquipmentCategory(models.Model): name = fields.Char('Category Name', required=True, translate=True) company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) technician_user_id = fields.Many2one('res.users', 'Responsible', tracking=True, default=lambda self: self.env.uid, oldname='user_id') color = fields.Integer('Color Index') note = fields.Text('Comments', translate=True) @@ -123,7 +123,7 @@ class MaintenanceEquipment(models.Model): name = fields.Char('Equipment Name', required=True, translate=True) company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) active = fields.Boolean(default=True) technician_user_id = fields.Many2one('res.users', string='Technician', tracking=True, oldname='user_id') owner_user_id = fields.Many2one('res.users', string='Owner', tracking=True) @@ -277,14 +277,14 @@ class MaintenanceRequest(models.Model): def _get_default_team_id(self): MT = self.env['maintenance.team'] - team = MT.search([('company_id', '=', self.env.company_id.id)], limit=1) + team = MT.search([('company_id', '=', self.env.company.id)], limit=1) if not team: team = MT.search([], limit=1) return team.id name = fields.Char('Subjects', required=True) company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) description = fields.Text('Description') request_date = fields.Date('Request Date', tracking=True, default=fields.Date.context_today, help="Date requested for the maintenance to happen") @@ -404,7 +404,7 @@ class MaintenanceTeam(models.Model): name = fields.Char(required=True, translate=True) active = fields.Boolean(default=True) company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) member_ids = fields.Many2many('res.users', 'maintenance_team_users_rel', string="Team Members") color = fields.Integer("Color Index", default=0) request_ids = fields.One2many('maintenance.request', 'maintenance_team_id', copy=False) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index a6d2ab4f297..6ace858bc78 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -61,7 +61,7 @@ class MrpBom(models.Model): "to define stock rules which trigger different manufacturing orders with different BoMs.") company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, required=True) consumption = fields.Selection([ ('strict', 'Strict'), diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index b13bcf51932..b502e08ac0a 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -22,7 +22,7 @@ class MrpProduction(models.Model): def _get_default_picking_type(self): return self.env['stock.picking.type'].search([ ('code', '=', 'mrp_operation'), - ('warehouse_id.company_id', 'in', [self.env.context.get('company_id', self.env.company_id.id), False])], + ('warehouse_id.company_id', 'in', [self.env.context.get('company_id', self.env.company.id), False])], limit=1).id @api.model @@ -35,7 +35,7 @@ class MrpProduction(models.Model): try: location.check_access_rule('read') except (AttributeError, AccessError): - location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id + location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id return location and location.id or False @api.model @@ -48,7 +48,7 @@ class MrpProduction(models.Model): try: location.check_access_rule('read') except (AttributeError, AccessError): - location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id + location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id return location and location.id or False name = fields.Char( @@ -179,7 +179,7 @@ class MrpProduction(models.Model): user_id = fields.Many2one('res.users', 'Responsible', default=lambda self: self._uid) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, required=True) qty_produced = fields.Float(compute="_get_produced_qty", string="Quantity Produced") @@ -419,7 +419,7 @@ class MrpProduction(models.Model): try: location.check_access_rule('read') except (AttributeError, AccessError): - location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id + location = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id self.move_raw_ids.update({'picking_type_id': self.picking_type_id}) self.location_src_id = self.picking_type_id.default_location_src_id.id or location.id self.location_dest_id = self.picking_type_id.default_location_dest_id.id or location.id diff --git a/addons/mrp/models/mrp_routing.py b/addons/mrp/models/mrp_routing.py index e2149c8b516..c79200ae8eb 100644 --- a/addons/mrp/models/mrp_routing.py +++ b/addons/mrp/models/mrp_routing.py @@ -22,7 +22,7 @@ class MrpRouting(models.Model): copy=True, oldname='workcenter_lines') company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) @api.model def create(self, vals): diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 09fa63fb813..a2628c69c78 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -18,7 +18,7 @@ class MrpUnbuild(models.Model): stock_location.check_access_rule('read') return stock_location.id except (AttributeError, AccessError): - return self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id.id + return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id.id def _get_default_location_dest_id(self): stock_location = self.env.ref('stock.stock_location_stock', raise_if_not_found=False) @@ -26,7 +26,7 @@ class MrpUnbuild(models.Model): stock_location.check_access_rule('read') return stock_location.id except (AttributeError, AccessError): - return self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id.id + return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id.id name = fields.Char('Reference', copy=False, readonly=True, default=lambda x: _('New')) product_id = fields.Many2one( diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py index 43a82173704..b67583361ca 100644 --- a/addons/mrp/report/mrp_report_bom_structure.py +++ b/addons/mrp/report/mrp_report_bom_structure.py @@ -58,7 +58,7 @@ class ReportBomStructure(models.AbstractModel): lines = self._get_operation_line(bom.routing_id, float_round(qty / bom.product_qty, precision_rounding=1, rounding_method='UP'), level) values = { 'bom_id': bom_id, - 'currency': self.env.company_id.currency_id, + 'currency': self.env.company.currency_id, 'operations': lines, } return self.env.ref('mrp.report_mrp_operation_line').render({'data': values}) @@ -111,7 +111,7 @@ class ReportBomStructure(models.AbstractModel): 'bom': bom, 'bom_qty': bom_quantity, 'bom_prod_name': product.display_name, - 'currency': self.env.company_id.currency_id, + 'currency': self.env.company.currency_id, 'product': product, 'code': bom and bom.display_name or '', 'price': product.uom_id._compute_price(product.standard_price, bom.product_uom_id) * bom_quantity, @@ -140,14 +140,14 @@ class ReportBomStructure(models.AbstractModel): sub_total = self._get_price(line.child_bom_id, factor, line.product_id) else: sub_total = price - sub_total = self.env.company_id.currency_id.round(sub_total) + sub_total = self.env.company.currency_id.round(sub_total) components.append({ 'prod_id': line.product_id.id, 'prod_name': line.product_id.display_name, 'code': line.child_bom_id and line.child_bom_id.display_name or '', 'prod_qty': line_quantity, 'prod_uom': line.product_uom_id.name, - 'prod_cost': self.env.company_id.currency_id.round(price), + 'prod_cost': self.env.company.currency_id.round(price), 'parent_id': bom.id, 'line_id': line.id, 'level': level or 0, @@ -173,7 +173,7 @@ class ReportBomStructure(models.AbstractModel): 'operation': operation, 'name': operation.name + ' - ' + operation.workcenter_id.name, 'duration_expected': duration_expected, - 'total': self.env.company_id.currency_id.round(total), + 'total': self.env.company.currency_id.round(total), }) return operations @@ -200,7 +200,7 @@ class ReportBomStructure(models.AbstractModel): else: prod_qty = line.product_qty * factor not_rounded_price = line.product_id.uom_id._compute_price(line.product_id.standard_price, line.product_uom_id) * prod_qty - price += self.env.company_id.currency_id.round(not_rounded_price) + price += self.env.company.currency_id.round(not_rounded_price) return price def _get_pdf_line(self, bom_id, product_id=False, qty=1, child_bom_ids=[], unfolded=False): diff --git a/addons/mrp_subcontracting/models/res_partner.py b/addons/mrp_subcontracting/models/res_partner.py index 08cac056884..925296fee0c 100644 --- a/addons/mrp_subcontracting/models/res_partner.py +++ b/addons/mrp_subcontracting/models/res_partner.py @@ -49,7 +49,7 @@ class ResPartner(models.Model): def write(self, vals): if vals.get('type') == 'subcontractor': - subcontracting_location = self.env.company_id.subcontracting_location_id + subcontracting_location = self.env.company.subcontracting_location_id if not vals.get('property_stock_supplier') and not vals.get('property_stock_customer'): vals['property_stock_supplier'] = subcontracting_location.id vals['property_stock_customer'] = subcontracting_location.id diff --git a/addons/pad/models/pad.py b/addons/pad/models/pad.py index 22cfe84af72..404e645e6f0 100644 --- a/addons/pad/models/pad.py +++ b/addons/pad/models/pad.py @@ -22,7 +22,7 @@ class PadCommon(models.AbstractModel): @api.model def pad_is_configured(self): - return bool(self.env.company_id.pad_server) + return bool(self.env.company.pad_server) @api.model def pad_generate_url(self): diff --git a/addons/partner_autocomplete/models/res_partner.py b/addons/partner_autocomplete/models/res_partner.py index a15d1626258..e0ed09a799d 100644 --- a/addons/partner_autocomplete/models/res_partner.py +++ b/addons/partner_autocomplete/models/res_partner.py @@ -90,8 +90,8 @@ class ResPartner(models.Model): params.update({ 'db_uuid': self.env['ir.config_parameter'].sudo().get_param('database.uuid'), 'account_token': account.account_token, - 'country_code': self.env.company_id.country_id.code, - 'zip': self.env.company_id.zip, + 'country_code': self.env.company.country_id.code, + 'zip': self.env.company.zip, }) try: return jsonrpc(url=url, params=params, timeout=timeout), False diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index 3d9ac23861b..a4da9dbbb34 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -106,7 +106,7 @@ class WebsitePayment(http.Controller): def payment_method(self, **kwargs): acquirers = list(request.env['payment.acquirer'].search([ ('website_published', '=', True), ('registration_view_template_id', '!=', False), - ('payment_flow', '=', 's2s'), ('company_id', '=', request.env.company_id.id) + ('payment_flow', '=', 's2s'), ('company_id', '=', request.env.company.id) ])) partner = request.env.user.partner_id payment_tokens = partner.payment_token_ids diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 087899880f2..21320cc04b3 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -72,7 +72,7 @@ class PaymentAcquirer(models.Model): default='manual', required=True) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id.id, required=True) + default=lambda self: self.env.company.id, required=True) view_template_id = fields.Many2one( 'ir.ui.view', 'Form Button Template', default=_get_default_view_template_id) @@ -267,7 +267,7 @@ class PaymentAcquirer(models.Model): acquirer_names = [a.name.split('_')[1] for a in acquirer_modules] # Search for acquirers having no journal - company = company or self.env.company_id + company = company or self.env.company acquirers = self.env['payment.acquirer'].search( [('provider', 'in', acquirer_names), ('journal_id', '=', False), ('company_id', '=', company.id)]) @@ -328,7 +328,7 @@ class PaymentAcquirer(models.Model): * pms: record set of stored credit card data (aka payment.token) connected to a given partner to allow customers to reuse them """ if not company: - company = self.env.company_id + company = self.env.company if not partner: partner = self.env.user.partner_id active_acquirers = self.sudo().search([('website_published', '=', True), ('company_id', '=', company.id)]) @@ -384,7 +384,7 @@ class PaymentAcquirer(models.Model): if currency_id: currency = self.env['res.currency'].browse(currency_id) else: - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id values['currency'] = currency # Fill partner_* using values['partner_id'] or partner_id argument @@ -569,7 +569,7 @@ class PaymentTransaction(models.Model): @api.model def _get_default_partner_country_id(self): - return self.env.company_id.country_id.id + return self.env.company.country_id.id date = fields.Datetime('Validation Date', readonly=True) acquirer_id = fields.Many2one('payment.acquirer', string='Acquirer', readonly=True, required=True) diff --git a/addons/payment/models/res_company.py b/addons/payment/models/res_company.py index a98ea1aac14..405fdff0745 100644 --- a/addons/payment/models/res_company.py +++ b/addons/payment/models/res_company.py @@ -20,7 +20,7 @@ class ResCompany(models.Model): def action_open_payment_onboarding_payment_acquirer(self): """ Called by onboarding panel above the customer invoice list.""" # Fail if there are no existing accounts - self.env.company_id.get_chart_of_accounts_or_fail() + self.env.company.get_chart_of_accounts_or_fail() action = self.env.ref('payment.action_open_payment_onboarding_payment_acquirer_wizard').read()[0] return action diff --git a/addons/payment/views/payment_portal_templates.xml b/addons/payment/views/payment_portal_templates.xml index 2b0c147260e..9eea5737022 100644 --- a/addons/payment/views/payment_portal_templates.xml +++ b/addons/payment/views/payment_portal_templates.xml @@ -33,7 +33,7 @@ <!-- TDE FIXME: was customize_show=True --> <template id="pay_meth_link" inherit_id="portal.portal_layout"> <xpath expr="//div[hasclass('o_portal_my_details')]" position="inside"> - <t t-if="request.env['payment.acquirer'].search([('website_published', '=', True), ('registration_view_template_id', '!=', False), ('payment_flow', '=', 's2s'), ('company_id', '=', request.env.company_id.id)])"> + <t t-if="request.env['payment.acquirer'].search([('website_published', '=', True), ('registration_view_template_id', '!=', False), ('payment_flow', '=', 's2s'), ('company_id', '=', request.env.company.id)])"> <div class='manage_payment_method mt16'><a href="/my/payment_method">Manage payment methods</a></div> </t> </xpath> diff --git a/addons/payment/wizards/payment_acquirer_onboarding_wizard.py b/addons/payment/wizards/payment_acquirer_onboarding_wizard.py index 38545771ae7..39c72656bf8 100644 --- a/addons/payment/wizards/payment_acquirer_onboarding_wizard.py +++ b/addons/payment/wizards/payment_acquirer_onboarding_wizard.py @@ -31,7 +31,7 @@ class PaymentWizard(models.TransientModel): @api.onchange('journal_name', 'acc_number') def _set_manual_post_msg_value(self): self.manual_post_msg = _('<h3>Please make a payment to: </h3><ul><li>Bank: %s</li><li>Account Number: %s</li><li>Account Holder: %s</li></ul>') %\ - (self.journal_name or _("Bank") , self.acc_number or _("Account"), self.env.company_id.name) + (self.journal_name or _("Bank") , self.acc_number or _("Account"), self.env.company.name) _payment_acquirer_onboarding_cache = {} _data_fetched = False @@ -41,7 +41,7 @@ class PaymentWizard(models.TransientModel): env = self.env module_id = env.ref('base.module_payment_transfer').id return env['payment.acquirer'].search([('module_id', '=', module_id), - ('company_id', '=', env.company_id.id)], limit=1) + ('company_id', '=', env.company.id)], limit=1) def _get_default_payment_acquirer_onboarding_value(self, key): if not self.env.user._is_admin(): @@ -52,7 +52,7 @@ class PaymentWizard(models.TransientModel): self._data_fetched = True - self._payment_acquirer_onboarding_cache['payment_method'] = self.env.company_id.payment_onboarding_payment_method + self._payment_acquirer_onboarding_cache['payment_method'] = self.env.company.payment_onboarding_payment_method installed_modules = self.env['ir.module.module'].sudo().search([ ('name', 'in', ('payment_paypal', 'payment_stripe')), @@ -103,7 +103,7 @@ class PaymentWizard(models.TransientModel): self._on_save_payment_acquirer() - self.env.company_id.payment_onboarding_payment_method = self.payment_method + self.env.company.payment_onboarding_payment_method = self.payment_method # create a new env including the freshly installed module(s) new_env = api.Environment(self.env.cr, self.env.uid, self.env.context) @@ -149,7 +149,7 @@ class PaymentWizard(models.TransientModel): return {'type': 'ir.actions.act_window_close'} def _set_payment_acquirer_onboarding_step_done(self): - self.env.company_id.set_onboarding_step_done('payment_acquirer_onboarding_state') + self.env.company.set_onboarding_step_done('payment_acquirer_onboarding_state') def action_onboarding_other_payment_acquirer(self): self._set_payment_acquirer_onboarding_step_done() diff --git a/addons/payment_transfer/models/payment.py b/addons/payment_transfer/models/payment.py index 98dd28aaa67..4464eb01309 100644 --- a/addons/payment_transfer/models/payment.py +++ b/addons/payment_transfer/models/payment.py @@ -18,7 +18,7 @@ class TransferPaymentAcquirer(models.Model): @api.model def _create_missing_journal_for_acquirers(self, company=None): # By default, the wire transfer method uses the default Bank journal. - company = company or self.env.company_id + company = company or self.env.company acquirers = self.env['payment.acquirer'].search( [('provider', '=', 'transfer'), ('journal_id', '=', False), ('company_id', '=', company.id)]) @@ -32,7 +32,7 @@ class TransferPaymentAcquirer(models.Model): return '/payment/transfer/feedback' def _format_transfer_data(self): - company_id = self.env.company_id.id + company_id = self.env.company.id # filter only bank accounts marked as visible journals = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', company_id)]) accounts = journals.mapped('bank_account_id').name_get() diff --git a/addons/phone_validation/models/phone_validation_mixin.py b/addons/phone_validation/models/phone_validation_mixin.py index 3ac75179a1e..f378387fc41 100644 --- a/addons/phone_validation/models/phone_validation_mixin.py +++ b/addons/phone_validation/models/phone_validation_mixin.py @@ -12,12 +12,12 @@ class PhoneValidationMixin(models.AbstractModel): def _phone_get_country(self): if 'country_id' in self and self.country_id: return self.country_id - return self.env.company_id.country_id + return self.env.company.country_id def _phone_get_always_international(self): if 'company_id' in self and self.company_id: return self.company_id.phone_international_format == 'prefix' - return self.env.company_id.phone_international_format == 'prefix' + return self.env.company.phone_international_format == 'prefix' def phone_format(self, number, country=None, company=None): country = country or self._phone_get_country() diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 1fbb51dacd8..e87ee562d3a 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -41,18 +41,18 @@ class PosConfig(models.Model): def _default_sale_journal(self): journal = self.env.ref('point_of_sale.pos_sale_journal', raise_if_not_found=False) - if journal and journal.sudo().company_id == self.env.company_id: + if journal and journal.sudo().company_id == self.env.company: return journal return self._default_invoice_journal() def _default_invoice_journal(self): - return self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.env.company_id.id)], limit=1) + return self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.env.company.id)], limit=1) def _default_pricelist(self): - return self.env['product.pricelist'].search([('currency_id', '=', self.env.company_id.currency_id.id)], limit=1) + return self.env['product.pricelist'].search([('currency_id', '=', self.env.company.currency_id.id)], limit=1) def _get_default_location(self): - return self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1).lot_stock_id + return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id def _get_group_pos_manager(self): return self.env.ref('point_of_sale.group_pos_manager') @@ -137,10 +137,10 @@ class PosConfig(models.Model): help="The pricelist used if no customer is selected or if the customer has no Sale Pricelist configured.") available_pricelist_ids = fields.Many2many('product.pricelist', string='Available Pricelists', default=_default_pricelist, help="Make several pricelists available in the Point of Sale. You can also apply a pricelist to specific customers from their contact form (in Sales tab). To be valid, this pricelist must be listed here as an available pricelist. Otherwise the default pricelist will apply.") - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', string='Barcode Nomenclature', help='Defines what kind of barcodes are available and how they are assigned to products, customers and cashiers.', - default=lambda self: self.env.company_id.nomenclature_id, required=True) + default=lambda self: self.env.company.nomenclature_id, required=True) group_pos_manager_id = fields.Many2one('res.groups', string='Point of Sale Manager Group', default=_get_group_pos_manager, help='This field is there to pass the id of the pos manager group to the point of sale client.') group_pos_user_id = fields.Many2one('res.groups', string='Point of Sale User Group', default=_get_group_pos_user, @@ -178,7 +178,7 @@ class PosConfig(models.Model): if pos_config.journal_id: pos_config.currency_id = pos_config.journal_id.currency_id.id or pos_config.journal_id.company_id.currency_id.id else: - pos_config.currency_id = self.env.company_id.currency_id.id + pos_config.currency_id = self.env.company.currency_id.id @api.depends('session_ids') def _compute_current_session(self): diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index cd943d8f9a5..33e7f55ee28 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -537,7 +537,7 @@ class PosOrder(models.Model): return self._default_session().config_id.pricelist_id name = fields.Char(string='Order Ref', required=True, readonly=True, copy=False, default='/') - company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) date_order = fields.Datetime(string='Order Date', readonly=True, index=True, default=fields.Datetime.now) user_id = fields.Many2one( comodel_name='res.users', string='User', @@ -1048,7 +1048,7 @@ class PosOrderLine(models.Model): line[2]['tax_ids'] = [(6, 0, [x.id for x in product.taxes_id])] return line - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) name = fields.Char(string='Line No', required=True, copy=False) notice = fields.Char(string='Discount Notice') product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)], required=True, change_default=True) @@ -1221,7 +1221,7 @@ class ReportSaleDetails(models.AbstractModel): orders = self.env['pos.order'].search(domain) - user_currency = self.env.company_id.currency_id + user_currency = self.env.company.currency_id total = 0.0 products_sold = {} @@ -1269,7 +1269,7 @@ class ReportSaleDetails(models.AbstractModel): 'currency_precision': user_currency.decimal_places, 'total_paid': user_currency.round(total), 'payments': payments, - 'company_name': self.env.company_id.name, + 'company_name': self.env.company.name, 'taxes': list(taxes.values()), 'products': sorted([{ 'product_id': product.id, diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index 200140ebb7e..0041ee18ea3 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -559,7 +559,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): # Make sure the company is in USD self.env.cr.execute( "UPDATE res_company SET currency_id = %s WHERE id = %s", - [self.env.ref('base.USD').id, self.env.company_id.id]) + [self.env.ref('base.USD').id, self.env.company.id]) # Demo data are crappy, clean-up the rates self.env['res.currency.rate'].search([]).unlink() diff --git a/addons/point_of_sale/wizard/pos_details.py b/addons/point_of_sale/wizard/pos_details.py index 2ce2224a7f5..6887bdb49a3 100644 --- a/addons/point_of_sale/wizard/pos_details.py +++ b/addons/point_of_sale/wizard/pos_details.py @@ -44,9 +44,9 @@ class PosDetails(models.TransientModel): @api.multi def generate_report(self): - if (not self.env.company_id.logo): + if (not self.env.company.logo): raise UserError(_("You have to set a logo or a layout for your company.")) - elif (not self.env.company_id.external_report_layout_id): + elif (not self.env.company.external_report_layout_id): raise UserError(_("You have to set your reports's header and footer layout.")) data = {'date_start': self.start_date, 'date_stop': self.end_date, 'config_ids': self.pos_config_ids.ids} return self.env.ref('point_of_sale.sale_details_report').report_action([], data=data) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 4c6942bbef7..de43d4e3d00 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -134,7 +134,7 @@ class PortalWizardUser(models.TransientModel): if wizard_user.partner_id.company_id: company_id = wizard_user.partner_id.company_id.id else: - company_id = self.env.company_id.id + company_id = self.env.company.id user_portal = wizard_user.sudo().with_context(company_id=company_id)._create_user() else: user_portal = user diff --git a/addons/product/models/decimal_precision.py b/addons/product/models/decimal_precision.py index 2fe33eed246..e8a46a90e2f 100644 --- a/addons/product/models/decimal_precision.py +++ b/addons/product/models/decimal_precision.py @@ -11,7 +11,7 @@ class DecimalPrecision(models.Model): @api.constrains('digits') def _check_main_currency_rounding(self): if any(precision.name == 'Account' and - tools.float_compare(self.env.company_id.currency_id.rounding, 10 ** - precision.digits, precision_digits=6) == -1 + tools.float_compare(self.env.company.currency_id.rounding, 10 ** - precision.digits, precision_digits=6) == -1 for precision in self): raise ValidationError(_("You cannot define the decimal precision of 'Account' as greater than the rounding factor of the company's main currency")) return True diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 6278173486c..a7cc6779f34 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -71,7 +71,7 @@ class ProductPriceHistory(models.Model): _description = 'Product Price List History' def _get_default_company_id(self): - return self._context.get('force_company', self.env.company_id.id) + return self._context.get('force_company', self.env.company.id) company_id = fields.Many2one('res.company', string='Company', default=_get_default_company_id, required=True) @@ -651,7 +651,7 @@ class ProductProduct(models.Model): # standard_price field can only be seen by users in base.group_user # Thus, in order to compute the sale price from the cost for users not in this group # We fetch the standard price as the superuser - products = self.with_context(force_company=company and company.id or self._context.get('force_company', self.env.company_id.id)).sudo() + products = self.with_context(force_company=company and company.id or self._context.get('force_company', self.env.company.id)).sudo() prices = dict.fromkeys(self.ids, 0.0) for product in products: @@ -689,7 +689,7 @@ class ProductProduct(models.Model): PriceHistory.create({ 'product_id': product.id, 'cost': value, - 'company_id': self._context.get('force_company', self.env.company_id.id), + 'company_id': self._context.get('force_company', self.env.company.id), }) @api.multi @@ -814,10 +814,10 @@ class SupplierInfo(models.Model): required=True, help="The price to purchase a product") company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id.id, index=1) + default=lambda self: self.env.company.id, index=1) currency_id = fields.Many2one( 'res.currency', 'Currency', - default=lambda self: self.env.company_id.currency_id.id, + default=lambda self: self.env.company.currency_id.id, required=True) date_start = fields.Date('Start Date', help="Start date for this vendor price") date_end = fields.Date('End Date', help="End date for this vendor price") diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 5f5e56e3a45..730d972405c 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -15,7 +15,7 @@ class Pricelist(models.Model): _order = "sequence asc, id desc" def _get_default_currency_id(self): - return self.env.company_id.currency_id.id + return self.env.company.currency_id.id def _get_default_item_ids(self): ProductPricelistItem = self.env['product.pricelist.item'] @@ -221,7 +221,7 @@ class Pricelist(models.Model): if rule.base == 'pricelist' and rule.base_pricelist_id: price_tmp = rule.base_pricelist_id._compute_price_rule([(product, qty, partner)])[product.id][0] # TDE: 0 = price, 1 = rule - price = rule.base_pricelist_id.currency_id._convert(price_tmp, self.currency_id, self.env.company_id, date, round=False) + price = rule.base_pricelist_id.currency_id._convert(price_tmp, self.currency_id, self.env.company, date, round=False) else: # if base option is public price take sale price else cost price of product # price_compute returns the price in the context UoM, i.e. qty_uom_id @@ -260,7 +260,7 @@ class Pricelist(models.Model): cur = product.cost_currency_id else: cur = product.currency_id - price = cur._convert(price, self.currency_id, self.env.company_id, date, round=False) + price = cur._convert(price, self.currency_id, self.env.company, date, round=False) results[product.id] = (price, suitable_rule and suitable_rule.id or False) @@ -353,7 +353,7 @@ class Pricelist(models.Model): # as we will do a search() later (real case for website public user). Partner = self.env['res.partner'].with_context(active_test=False) - Property = self.env['ir.property'].with_context(force_company=company_id or self.env.company_id.id) + Property = self.env['ir.property'].with_context(force_company=company_id or self.env.company.id) Pricelist = self.env['product.pricelist'] pl_domain = self._get_partner_pricelist_multi_search_domain_hook() diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index be0d3c8aec1..dbbb3d488f9 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -109,7 +109,7 @@ class ProductTemplate(models.Model): help="Default unit of measure used for purchase orders. It must be in the same category as the default unit of measure.") company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, index=1) + default=lambda self: self.env.company, index=1) packaging_ids = fields.One2many( 'product.packaging', string="Product Packages", compute="_compute_packaging_ids", inverse="_set_packaging_ids", help="Gives the different ways to package the same product.") @@ -168,7 +168,7 @@ class ProductTemplate(models.Model): def _compute_cost_currency_id(self): for template in self: - template.cost_currency_id = self.env.company_id.currency_id.id + template.cost_currency_id = self.env.company.currency_id.id @api.multi def _compute_template_price(self): @@ -453,12 +453,12 @@ class ProductTemplate(models.Model): # standard_price field can only be seen by users in base.group_user # Thus, in order to compute the sale price from the cost for users not in this group # We fetch the standard price as the superuser - templates = self.with_context(force_company=company and company.id or self._context.get('force_company', self.env.company_id.id)).sudo() + templates = self.with_context(force_company=company and company.id or self._context.get('force_company', self.env.company.id)).sudo() if not company: if self._context.get('force_company'): company = self.env['res.company'].browse(self._context['force_company']) else: - company = self.env.company_id + company = self.env.company date = self.env.context.get('date') or fields.Date.today() prices = dict.fromkeys(self.ids, 0.0) @@ -1093,7 +1093,7 @@ class ProductTemplate(models.Model): :rtype: recordset of one `res.company` """ self.ensure_one() - return self.env.company_id + return self.env.company @api.model def get_empty_list_help(self, help): diff --git a/addons/product/models/res_partner.py b/addons/product/models/res_partner.py index c36a791f043..be1f7f25d41 100644 --- a/addons/product/models/res_partner.py +++ b/addons/product/models/res_partner.py @@ -34,7 +34,7 @@ class Partner(models.Model): # update at each change country, and so erase old pricelist if self.property_product_pricelist or (actual and default_for_country and default_for_country.id != actual.id): # keep the company of the current user before sudo - self.env['ir.property'].with_context(force_company=self.env.company_id.id).sudo().set_multi( + self.env['ir.property'].with_context(force_company=self.env.company.id).sudo().set_multi( 'property_product_pricelist', self._name, {self.id: self.property_product_pricelist or default_for_country.id}, diff --git a/addons/product/tests/test_seller.py b/addons/product/tests/test_seller.py index ee87f7833f6..637c59b78c9 100644 --- a/addons/product/tests/test_seller.py +++ b/addons/product/tests/test_seller.py @@ -33,7 +33,7 @@ class TestSeller(TransactionCase): self.assertEqual('C2CCODE', context_code, "Partner's code not used in product name with context set") def test_20_sellers_company(self): - company_a = self.env.company_id + company_a = self.env.company company_b = self.env['res.company'].create({ 'name': 'Saucisson Inc.', }) diff --git a/addons/product/wizard/product_price_list.py b/addons/product/wizard/product_price_list.py index 743b32f3855..2488d8c335a 100644 --- a/addons/product/wizard/product_price_list.py +++ b/addons/product/wizard/product_price_list.py @@ -22,9 +22,9 @@ class product_price_list(models.TransientModel): To get the date and print the report @return : return report """ - if (not self.env.company_id.logo): + if (not self.env.company.logo): raise UserError(_("You have to set a logo or a layout for your company.")) - elif (not self.env.company_id.external_report_layout_id): + elif (not self.env.company.external_report_layout_id): raise UserError(_("You have to set your reports's header and footer layout.")) datas = {'ids': self.env.context.get('active_ids', [])} diff --git a/addons/product_margin/models/product_product.py b/addons/product_margin/models/product_product.py index 5f8ca4002d1..5e4d5565b59 100644 --- a/addons/product_margin/models/product_product.py +++ b/addons/product_margin/models/product_product.py @@ -100,7 +100,7 @@ class ProductProduct(models.Model): if "force_company" in self.env.context: company_id = self.env.context['force_company'] else: - company_id = self.env.company_id.id + company_id = self.env.company.id #Cost price is calculated afterwards as it is a property sqlstr = """ diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 627ec77b643..b9c597edd8e 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -171,7 +171,7 @@ class Project(models.Model): help="If the active field is set to False, it will allow you to hide the project without removing it.") sequence = fields.Integer(default=10, help="Gives the sequence order when displaying a list of Projects.") partner_id = fields.Many2one('res.partner', string='Customer', auto_join=True, tracking=True) - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', related="company_id.currency_id", string="Currency", readonly=True) analytic_account_id = fields.Many2one('account.analytic.account', string="Analytic Account", copy=False, ondelete='set null', help="Analytic account to which this project is linked for financial management. " @@ -187,7 +187,7 @@ class Project(models.Model): tasks = fields.One2many('project.task', 'project_id', string="Task Activities") resource_calendar_id = fields.Many2one( 'resource.calendar', string='Working Time', - default=lambda self: self.env.company_id.resource_calendar_id.id, + default=lambda self: self.env.company.resource_calendar_id.id, help="Timetable working hours to adjust the gantt diagram report") type_ids = fields.Many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', string='Tasks Stages') task_count = fields.Integer(compute='_compute_task_count', string="Task Count") @@ -522,7 +522,7 @@ class Task(models.Model): manager_id = fields.Many2one('res.users', string='Project Manager', related='project_id.user_id', readonly=True, related_sudo=False) company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) color = fields.Integer(string='Color Index') user_email = fields.Char(related='user_id.email', string='User Email', readonly=True, related_sudo=False) attachment_ids = fields.One2many('ir.attachment', compute='_compute_attachment_ids', string="Main Attachments", diff --git a/addons/project_timesheet_holidays/__init__.py b/addons/project_timesheet_holidays/__init__.py index cfae265bb38..388eef6f439 100644 --- a/addons/project_timesheet_holidays/__init__.py +++ b/addons/project_timesheet_holidays/__init__.py @@ -13,7 +13,7 @@ def post_init(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) for hr_leave_type in env['hr.leave.type'].search([('timesheet_generate', '=', True), ('timesheet_project_id', '=', False)]): - company = hr_leave_type.company_id or env.company_id + company = hr_leave_type.company_id or env.company hr_leave_type.write({ 'timesheet_project_id': company.leave_timesheet_project_id.id, 'timesheet_task_id': company.leave_timesheet_task_id.id, diff --git a/addons/project_timesheet_holidays/models/hr_holidays.py b/addons/project_timesheet_holidays/models/hr_holidays.py index eacbae5e2ba..ada3b56acc1 100644 --- a/addons/project_timesheet_holidays/models/hr_holidays.py +++ b/addons/project_timesheet_holidays/models/hr_holidays.py @@ -9,11 +9,11 @@ class HolidaysType(models.Model): _inherit = "hr.leave.type" def _default_project_id(self): - company = self.company_id if self.company_id else self.env.company_id + company = self.company_id if self.company_id else self.env.company return company.leave_timesheet_project_id.id def _default_task_id(self): - company = self.company_id if self.company_id else self.env.company_id + company = self.company_id if self.company_id else self.env.company return company.leave_timesheet_task_id.id timesheet_generate = fields.Boolean('Generate Timesheet', default=True, help="If checked, when validating a time off, timesheet will be generated in the Vacation Project of the company.") @@ -29,7 +29,7 @@ class HolidaysType(models.Model): @api.onchange('timesheet_project_id') def _onchange_timesheet_project(self): - company = self.company_id if self.company_id else self.env.company_id + company = self.company_id if self.company_id else self.env.company default_task_id = company.leave_timesheet_task_id if default_task_id and default_task_id.project_id == self.timesheet_project_id: self.timesheet_task_id = default_task_id diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py index 5effe0e5c37..a44d2fcde17 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py @@ -19,7 +19,7 @@ class TestTimesheetHolidaysCreate(common.TransactionCase): 'allocation_type': 'no' }) - company = self.env.company_id + company = self.env.company self.assertEqual(status.timesheet_project_id, company.leave_timesheet_project_id, 'The default project linked to the status should be the same as the company') self.assertEqual(status.timesheet_task_id, company.leave_timesheet_task_id, 'The default task linked to the status should be the same as the company') @@ -37,8 +37,8 @@ class TestTimesheetHolidays(TestCommonTimesheet): self.leave_end_datetime = self.leave_start_datetime + relativedelta(days=3) # all company have those internal project/task (created by default) - self.internal_project = self.env.company_id.leave_timesheet_project_id - self.internal_task_leaves = self.env.company_id.leave_timesheet_task_id + self.internal_project = self.env.company.leave_timesheet_project_id + self.internal_task_leaves = self.env.company.leave_timesheet_task_id self.hr_leave_type_with_ts = self.env['hr.leave.type'].create({ 'name': 'Leave Type with timesheet generation', diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index beb9381565b..150c5c02cb9 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -74,7 +74,7 @@ class AccountInvoice(models.Model): 'analytic_tag_ids': line.analytic_tag_ids.ids, 'invoice_line_tax_ids': invoice_line_tax_ids.ids } - account = invoice_line.get_invoice_line_account('in_invoice', line.product_id, line.order_id.fiscal_position_id, self.env.company_id) + account = invoice_line.get_invoice_line_account('in_invoice', line.product_id, line.order_id.fiscal_position_id, self.env.company) if account: data['account_id'] = account.id return data diff --git a/addons/purchase/models/product.py b/addons/purchase/models/product.py index dcdccd180b6..566805ebbc2 100644 --- a/addons/purchase/models/product.py +++ b/addons/purchase/models/product.py @@ -97,4 +97,4 @@ class ProductSupplierinfo(models.Model): @api.onchange('name') def _onchange_name(self): - self.currency_id = self.name.property_purchase_currency_id.id or self.env.company_id.currency_id.id + self.currency_id = self.name.property_purchase_currency_id.id or self.env.company.currency_id.id diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 05cf80ce017..fb68ccdec72 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -91,7 +91,7 @@ class PurchaseOrder(models.Model): help="Put an address if you want to deliver directly from the vendor to the customer. " "Otherwise, keep empty to deliver to your own company.") currency_id = fields.Many2one('res.currency', 'Currency', required=True, states=READONLY_STATES, - default=lambda self: self.env.company_id.currency_id.id) + default=lambda self: self.env.company.currency_id.id) state = fields.Selection([ ('draft', 'RFQ'), ('sent', 'RFQ Sent'), @@ -124,7 +124,7 @@ class PurchaseOrder(models.Model): product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product', readonly=False) user_id = fields.Many2one('res.users', string='Purchase Representative', index=True, tracking=True, default=lambda self: self.env.user) - company_id = fields.Many2one('res.company', 'Company', required=True, index=True, states=READONLY_STATES, default=lambda self: self.env.company_id.id) + company_id = fields.Many2one('res.company', 'Company', required=True, index=True, states=READONLY_STATES, default=lambda self: self.env.company.id) def _compute_access_url(self): super(PurchaseOrder, self)._compute_access_url() @@ -192,11 +192,11 @@ class PurchaseOrder(models.Model): if not self.partner_id: self.fiscal_position_id = False self.payment_term_id = False - self.currency_id = self.env.company_id.currency_id.id + self.currency_id = self.env.company.currency_id.id else: self.fiscal_position_id = self.env['account.fiscal.position'].with_context(company_id=self.company_id.id).get_fiscal_position(self.partner_id.id) self.payment_term_id = self.partner_id.property_supplier_payment_term_id.id - self.currency_id = self.partner_id.property_purchase_currency_id.id or self.env.company_id.currency_id.id + self.currency_id = self.partner_id.property_purchase_currency_id.id or self.env.company.currency_id.id return {} @api.onchange('fiscal_position_id') @@ -325,7 +325,7 @@ class PurchaseOrder(models.Model): # Deal with double validation process if order.company_id.po_double_validation == 'one_step'\ or (order.company_id.po_double_validation == 'two_step'\ - and order.amount_total < self.env.company_id.currency_id._convert( + and order.amount_total < self.env.company.currency_id._convert( order.company_id.po_double_validation_amount, order.currency_id, order.company_id, order.date_order or fields.Date.today()))\ or order.user_has_groups('purchase.group_purchase_manager'): order.button_approve() @@ -359,7 +359,7 @@ class PurchaseOrder(models.Model): # Do not add a contact as a supplier partner = self.partner_id if not self.partner_id.parent_id else self.partner_id.parent_id if partner not in line.product_id.seller_ids.mapped('name') and len(line.product_id.seller_ids) <= 10: - currency = partner.property_purchase_currency_id or self.env.company_id.currency_id + currency = partner.property_purchase_currency_id or self.env.company.currency_id supplierinfo = { 'name': partner.id, 'sequence': max(line.product_id.seller_ids.mapped('sequence')) + 1 if line.product_id.seller_ids else 1, @@ -609,7 +609,7 @@ class PurchaseOrderLine(models.Model): fpos = self.order_id.fiscal_position_id if self.env.uid == SUPERUSER_ID: - company_id = self.env.company_id.id + company_id = self.env.company.id self.taxes_id = fpos.map_tax(self.product_id.supplier_taxes_id.filtered(lambda r: r.company_id.id == company_id)) else: self.taxes_id = fpos.map_tax(self.product_id.supplier_taxes_id) diff --git a/addons/purchase/models/res_config_settings.py b/addons/purchase/models/res_config_settings.py index 72fc6c91f0b..2b5358a250f 100644 --- a/addons/purchase/models/res_config_settings.py +++ b/addons/purchase/models/res_config_settings.py @@ -7,9 +7,9 @@ from odoo import api, fields, models class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' - lock_confirmed_po = fields.Boolean("Lock Confirmed Orders", default=lambda self: self.env.company_id.po_lock == 'lock') + lock_confirmed_po = fields.Boolean("Lock Confirmed Orders", default=lambda self: self.env.company.po_lock == 'lock') po_lock = fields.Selection(related='company_id.po_lock', string="Purchase Order Modification *", readonly=False) - po_order_approval = fields.Boolean("Purchase Order Approval", default=lambda self: self.env.company_id.po_double_validation == 'two_step') + po_order_approval = fields.Boolean("Purchase Order Approval", default=lambda self: self.env.company.po_double_validation == 'two_step') po_double_validation = fields.Selection(related='company_id.po_double_validation', string="Levels of Approvals *", readonly=False) po_double_validation_amount = fields.Monetary(related='company_id.po_double_validation_amount', string="Minimum Amount", currency_field='company_currency_id', readonly=False) company_currency_id = fields.Many2one('res.currency', related='company_id.currency_id', string="Company Currency", readonly=True, diff --git a/addons/purchase_requisition/models/purchase_requisition.py b/addons/purchase_requisition/models/purchase_requisition.py index 19aa1240499..7abaa4e1332 100644 --- a/addons/purchase_requisition/models/purchase_requisition.py +++ b/addons/purchase_requisition/models/purchase_requisition.py @@ -56,7 +56,7 @@ class PurchaseRequisition(models.Model): schedule_date = fields.Date(string='Delivery Date', index=True, help="The expected and scheduled delivery date where all the products are received", tracking=True) user_id = fields.Many2one('res.users', string='Purchase Representative', default= lambda self: self.env.user) description = fields.Text() - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) purchase_ids = fields.One2many('purchase.order', 'requisition_id', string='Purchase Orders', states={'done': [('readonly', True)]}) line_ids = fields.One2many('purchase.requisition.line', 'requisition_id', string='Products to Purchase', states={'done': [('readonly', True)]}, copy=True) state = fields.Selection(PURCHASE_REQUISITION_STATES, @@ -65,7 +65,7 @@ class PurchaseRequisition(models.Model): state_blanket_order = fields.Selection(PURCHASE_REQUISITION_STATES, compute='_set_state') is_quantity_copy = fields.Selection(related='type_id.quantity_copy', readonly=True) currency_id = fields.Many2one('res.currency', 'Currency', required=True, - default=lambda self: self.env.company_id.currency_id.id) + default=lambda self: self.env.company.currency_id.id) @api.depends('state') def _set_state(self): @@ -181,7 +181,7 @@ class PurchaseRequisitionLine(models.Model): price_unit = fields.Float(string='Unit Price', digits=dp.get_precision('Product Price')) qty_ordered = fields.Float(compute='_compute_ordered_qty', string='Ordered Quantities') requisition_id = fields.Many2one('purchase.requisition', required=True, string='Purchase Agreement', ondelete='cascade') - company_id = fields.Many2one('res.company', related='requisition_id.company_id', string='Company', store=True, readonly=True, default= lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', related='requisition_id.company_id', string='Company', store=True, readonly=True, default= lambda self: self.env.company) account_analytic_id = fields.Many2one('account.analytic.account', string='Analytic Account') analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags') schedule_date = fields.Date(string='Scheduled Date') diff --git a/addons/purchase_requisition_stock/models/purchase_requisition.py b/addons/purchase_requisition_stock/models/purchase_requisition.py index 35950316af3..272612a6344 100644 --- a/addons/purchase_requisition_stock/models/purchase_requisition.py +++ b/addons/purchase_requisition_stock/models/purchase_requisition.py @@ -9,7 +9,7 @@ class PurchaseRequisition(models.Model): def _get_picking_in(self): pick_in = self.env.ref('stock.picking_type_in', raise_if_not_found=False) - company = self.env.company_id + company = self.env.company if not pick_in or pick_in.sudo().warehouse_id.company_id.id != company.id: pick_in = self.env['stock.picking.type'].search( [('warehouse_id.company_id', '=', company.id), ('code', '=', 'incoming')], diff --git a/addons/purchase_requisition_stock/tests/test_purchase_requisition_stock.py b/addons/purchase_requisition_stock/tests/test_purchase_requisition_stock.py index b592d64f571..ce440d451fa 100644 --- a/addons/purchase_requisition_stock/tests/test_purchase_requisition_stock.py +++ b/addons/purchase_requisition_stock/tests/test_purchase_requisition_stock.py @@ -19,7 +19,7 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon): warehouse.lot_stock_id, '/', '/', - self.env.company_id, + self.env.company, { 'warehouse_id': warehouse, 'date_planned': date_planned, diff --git a/addons/purchase_stock/models/account_invoice.py b/addons/purchase_stock/models/account_invoice.py index bb3eaea506f..c6d138352cf 100644 --- a/addons/purchase_stock/models/account_invoice.py +++ b/addons/purchase_stock/models/account_invoice.py @@ -12,7 +12,7 @@ class AccountInvoice(models.Model): def invoice_line_move_line_get(self): res = super(AccountInvoice, self).invoice_line_move_line_get() - if self.env.company_id.anglo_saxon_accounting: + if self.env.company.anglo_saxon_accounting: if self.type in ['in_invoice', 'in_refund']: for i_line in self.invoice_line_ids: res.extend(self._anglo_saxon_purchase_move_lines(i_line, res)) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 40b14c52c7a..f03a4391990 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -15,7 +15,7 @@ class PurchaseOrder(models.Model): @api.model def _default_picking_type(self): type_obj = self.env['stock.picking.type'] - company_id = self.env.context.get('company_id') or self.env.company_id.id + company_id = self.env.context.get('company_id') or self.env.company.id types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)]) if not types: types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index eaa99b75d73..b6f633b5370 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -267,7 +267,7 @@ class StockRule(models.Model): 'user_id': False, 'picking_type_id': self.picking_type_id.id, 'company_id': company_id.id, - 'currency_id': partner.with_context(force_company=company_id.id).property_purchase_currency_id.id or self.env.company_id.currency_id.id, + 'currency_id': partner.with_context(force_company=company_id.id).property_purchase_currency_id.id or self.env.company.currency_id.id, 'dest_address_id': values.get('partner_id', False), 'origin': ', '.join(origins), 'payment_term_id': partner.with_context(force_company=company_id.id).property_supplier_payment_term_id.id, diff --git a/addons/purchase_stock/tests/common.py b/addons/purchase_stock/tests/common.py index 1abed5a751e..5a5281f25e1 100644 --- a/addons/purchase_stock/tests/common.py +++ b/addons/purchase_stock/tests/common.py @@ -19,7 +19,7 @@ class TestPurchase(TestStockCommon): } return ProcurementGroup.run([self.env['procurement.group'].Procurement( product, product_qty, self.uom_unit, self.warehouse_1.lot_stock_id, - product.name, '/', self.env.company_id, order_values) + product.name, '/', self.env.company, order_values) ]) def _load(self, module, *args): diff --git a/addons/purchase_stock/tests/test_create_picking.py b/addons/purchase_stock/tests/test_create_picking.py index 7beafab87e7..d8a9a37fef6 100644 --- a/addons/purchase_stock/tests/test_create_picking.py +++ b/addons/purchase_stock/tests/test_create_picking.py @@ -76,7 +76,7 @@ class TestCreatePicking(common.TestProductCommon): def test_01_check_double_validation(self): # make double validation two step - self.env.company_id.write({'po_double_validation': 'two_step','po_double_validation_amount':2000.00}) + self.env.company.write({'po_double_validation': 'two_step','po_double_validation_amount':2000.00}) # Draft purchase order created self.po = self.env['purchase.order'].sudo(self.user_purchase_user).create(self.po_vals) diff --git a/addons/purchase_stock/tests/test_purchase_lead_time.py b/addons/purchase_stock/tests/test_purchase_lead_time.py index 4d8fbb0ab28..f14c3dc9df1 100644 --- a/addons/purchase_stock/tests/test_purchase_lead_time.py +++ b/addons/purchase_stock/tests/test_purchase_lead_time.py @@ -102,7 +102,7 @@ class TestPurchaseLeadTime(TestPurchase): date_planned = fields.Datetime.to_string(fields.datetime.now() + timedelta(days=10)) # Create procurement order of product_1 self.env['procurement.group'].run([self.env['procurement.group'].Procurement( - self.product_1, 5.000, self.uom_unit, self.warehouse_1.lot_stock_id, 'Test scheduler for RFQ', '/', self.env.company_id, + self.product_1, 5.000, self.uom_unit, self.warehouse_1.lot_stock_id, 'Test scheduler for RFQ', '/', self.env.company, { 'warehouse_id': self.warehouse_1, 'date_planned': date_planned, # 10 days added to current date of procurement to get future schedule date and order date of purchase order. diff --git a/addons/purchase_stock/tests/test_stockvaluation.py b/addons/purchase_stock/tests/test_stockvaluation.py index 604abc205ee..69208fd9080 100644 --- a/addons/purchase_stock/tests/test_stockvaluation.py +++ b/addons/purchase_stock/tests/test_stockvaluation.py @@ -147,7 +147,7 @@ class TestStockValuation(TransactionCase): """ self.env['res.currency.rate'].search([]).unlink() usd_currency = self.env.ref('base.USD') - self.env.company_id.currency_id = usd_currency.id + self.env.company.currency_id = usd_currency.id eur_currency = self.env.ref('base.EUR') @@ -176,7 +176,7 @@ class TestStockValuation(TransactionCase): # convert the price unit in the company currency price_unit_usd = po1.currency_id._convert( po1.order_line.price_unit, po1.company_id.currency_id, - self.env.company_id, fields.Date.today(), round=False) + self.env.company, fields.Date.today(), round=False) # the unit price of the move is the unit price of the purchase order line converted in # the company's currency @@ -192,7 +192,7 @@ class TestStockValuation(TransactionCase): eur_currency._compute_current_rate() price_unit_usd_new_rate = po1.currency_id._convert( po1.order_line.price_unit, po1.company_id.currency_id, - self.env.company_id, fields.Date.today(), round=False) + self.env.company, fields.Date.today(), round=False) # the new price_unit is lower than th initial because of the rate's change self.assertLess(price_unit_usd_new_rate, price_unit_usd) @@ -330,7 +330,7 @@ class TestStockValuationWithCOA(AccountingTestCase): }) def test_fifo_anglosaxon_return(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' self.product1.product_tmpl_id.invoice_policy = 'delivery' @@ -426,7 +426,7 @@ class TestStockValuationWithCOA(AccountingTestCase): self.assertEqual(price_diff_entry.credit, 100) def test_anglosaxon_valuation(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' self.product1.product_tmpl_id.invoice_policy = 'delivery' diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 9a839d1ffc6..3e4593e5427 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -109,7 +109,7 @@ class Repair(models.Model): quotation_notes = fields.Text('Quotation Notes') company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) invoiced = fields.Boolean('Invoiced', copy=False, readonly=True) repaired = fields.Boolean('Repaired', copy=False, readonly=True) amount_untaxed = fields.Float('Untaxed Amount', compute='_amount_untaxed', store=True) diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index 41a19a45890..57a43482dac 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -169,7 +169,7 @@ class ResourceCalendar(models.Model): name = fields.Char(required=True) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) attendance_ids = fields.One2many( 'resource.calendar.attendance', 'calendar_id', 'Working Time', copy=True) @@ -446,7 +446,7 @@ class ResourceResource(models.Model): active = fields.Boolean( 'Active', default=True, tracking=True, help="If the active field is set to False, it will allow you to hide the resource record without removing it.") - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) resource_type = fields.Selection([ ('user', 'Human'), ('material', 'Material')], string='Resource Type', @@ -457,7 +457,7 @@ class ResourceResource(models.Model): help="This field is used to calculate the the expected duration of a work order at this work center. For example, if a work order takes one hour and the efficiency factor is 100%, then the expected duration will be one hour. If the efficiency factor is 200%, however the expected duration will be 30 minutes.") calendar_id = fields.Many2one( "resource.calendar", string='Working Time', - default=lambda self: self.env.company_id.resource_calendar_id, + default=lambda self: self.env.company.resource_calendar_id, required=True, help="Define the schedule of resource") tz = fields.Selection( diff --git a/addons/resource/models/resource_mixin.py b/addons/resource/models/resource_mixin.py index 9fed050cddf..32d2a2d3ae0 100644 --- a/addons/resource/models/resource_mixin.py +++ b/addons/resource/models/resource_mixin.py @@ -27,11 +27,11 @@ class ResourceMixin(models.AbstractModel): auto_join=True, index=True, ondelete='restrict', required=True) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, index=True, related='resource_id.company_id', store=True, readonly=False) resource_calendar_id = fields.Many2one( 'resource.calendar', 'Working Hours', - default=lambda self: self.env.company_id.resource_calendar_id, + default=lambda self: self.env.company.resource_calendar_id, index=True, related='resource_id.calendar_id', store=True, readonly=False) tz = fields.Selection( string='Timezone', related='resource_id.tz', readonly=False, diff --git a/addons/sale/controllers/onboarding.py b/addons/sale/controllers/onboarding.py index aa8ad05a189..433824afdc9 100644 --- a/addons/sale/controllers/onboarding.py +++ b/addons/sale/controllers/onboarding.py @@ -13,7 +13,7 @@ class OnboardingController(http.Controller): It can be empty if the user has closed it or if he doesn't have the permission to see it. """ - company = request.env.company_id + company = request.env.company if not request.env.user._is_admin() or \ company.sale_quotation_onboarding_state == 'closed': return {} diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index f24dbf66d6a..f439341bd29 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -43,7 +43,7 @@ class AccountInvoice(models.Model): self.partner_shipping_id = addr and addr.get('delivery') inv_type = self.type or self.env.context.get('type', 'out_invoice') if inv_type == 'out_invoice': - company = self.company_id or self.env.company_id + company = self.company_id or self.env.company self.comment = company.with_context(lang=self.partner_id.lang).invoice_terms @api.multi diff --git a/addons/sale/models/res_company.py b/addons/sale/models/res_company.py index 6687f0f8881..4845a565bf9 100644 --- a/addons/sale/models/res_company.py +++ b/addons/sale/models/res_company.py @@ -27,12 +27,12 @@ class ResCompany(models.Model): @api.model def action_close_sale_quotation_onboarding(self): """ Mark the onboarding panel as closed. """ - self.env.company_id.sale_quotation_onboarding_state = 'closed' + self.env.company.sale_quotation_onboarding_state = 'closed' @api.model def action_open_sale_onboarding_payment_acquirer(self): """ Called by onboarding panel above the quotation list.""" - self.env.company_id.get_chart_of_accounts_or_fail() + self.env.company.get_chart_of_accounts_or_fail() action = self.env.ref('sale.action_open_sale_onboarding_payment_acquirer_wizard').read()[0] return action @@ -40,7 +40,7 @@ class ResCompany(models.Model): """ Get a sample quotation or create one if it does not exist. """ # use current user as partner partner = self.env.user.partner_id - company_id = self.env.company_id.id + company_id = self.env.company.id # is there already one? sample_sales_order = self.env['sale.order'].search( [('company_id', '=', company_id), ('partner_id', '=', partner.id), @@ -107,7 +107,7 @@ class ResCompany(models.Model): def action_open_sale_onboarding_quotation_layout(self): """ Onboarding step for the quotation layout. """ action = self.env.ref('sale.action_open_sale_onboarding_quotation_layout').read()[0] - action['res_id'] = self.env.company_id.id + action['res_id'] = self.env.company.id return action _sql_constraints = [('check_quotation_validity_days', 'CHECK(quotation_validity_days > 0)', 'Quotation Validity is required and must be greater than 0.')] diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index f33c26920fe..952fbbdde05 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -25,16 +25,16 @@ class SaleOrder(models.Model): def _default_validity_date(self): if self.env['ir.config_parameter'].sudo().get_param('sale.use_quotation_validity_days'): - days = self.env.company_id.quotation_validity_days + days = self.env.company.quotation_validity_days if days > 0: return fields.Date.to_string(datetime.now() + timedelta(days)) return False def _get_default_require_signature(self): - return self.env.company_id.portal_confirmation_sign + return self.env.company.portal_confirmation_sign def _get_default_require_payment(self): - return self.env.company_id.portal_confirmation_pay + return self.env.company.portal_confirmation_pay @api.depends('order_line.price_total') def _amount_all(self): @@ -101,7 +101,7 @@ class SaleOrder(models.Model): @api.model def _default_note(self): - return self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company_id.invoice_terms or '' + return self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company.invoice_terms or '' @api.model def _get_default_team(self): @@ -175,7 +175,7 @@ class SaleOrder(models.Model): payment_term_id = fields.Many2one('account.payment.term', string='Payment Terms', oldname='payment_term', help="Payment terms applies to all invoices issued from this order.") fiscal_position_id = fields.Many2one('account.fiscal.position', oldname='fiscal_position', string='Fiscal Position', help=" Fiscal positions are used to adapt taxes and accounts for particular customers or sales orders/invoices. The default value comes from the customer.") - company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company) team_id = fields.Many2one('crm.team', 'Sales Team', change_default=True, default=_get_default_team, oldname='section_id') signature = fields.Binary('Signature', help='Signature received through the portal.', copy=False, attachment=True) @@ -310,8 +310,8 @@ class SaleOrder(models.Model): 'partner_shipping_id': addr['delivery'], 'user_id': self.partner_id.user_id.id or self.partner_id.commercial_partner_id.user_id.id or self.env.uid } - if self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company_id.invoice_terms: - values['note'] = self.with_context(lang=self.partner_id.lang).env.company_id.invoice_terms + if self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company.invoice_terms: + values['note'] = self.with_context(lang=self.partner_id.lang).env.company.invoice_terms # Use team of saleman before to fallback on team of partner. values['team_id'] = self.partner_id.user_id and self.partner_id.user_id.sale_team_id.id or self.partner_id.team_id.id @@ -659,7 +659,7 @@ class SaleOrder(models.Model): def message_post(self, **kwargs): if self.env.context.get('mark_so_as_sent'): self.filtered(lambda o: o.state == 'draft').with_context(tracking_disable=True).write({'state': 'sent'}) - self.env.company_id.set_onboarding_step_done('sale_onboarding_sample_quotation_state') + self.env.company.set_onboarding_step_done('sale_onboarding_sample_quotation_state') return super(SaleOrder, self.with_context(mail_post_autofollow=True)).message_post(**kwargs) @api.multi @@ -1569,7 +1569,7 @@ class SaleOrderLine(models.Model): product_currency = pricelist_item.base_pricelist_id.currency_id currency_id = pricelist_item.pricelist_id.currency_id - product_currency = product_currency or(product.company_id and product.company_id.currency_id) or self.env.company_id.currency_id + product_currency = product_currency or(product.company_id and product.company_id.currency_id) or self.env.company.currency_id if not currency_id: currency_id = product_currency cur_factor = 1.0 diff --git a/addons/sale/tests/test_onchange.py b/addons/sale/tests/test_onchange.py index 768cd96f54b..dbb5c6b83d1 100644 --- a/addons/sale/tests/test_onchange.py +++ b/addons/sale/tests/test_onchange.py @@ -226,9 +226,9 @@ class TestOnchangeProductId(TransactionCase): self.env['res.currency.rate'].create({'name': '2018-07-11', 'rate': 2.0, 'currency_id': other_currency.id, - 'company_id': self.env.company_id.id}) + 'company_id': self.env.company.id}) self.env['res.currency.rate'].search( - [('currency_id', '=', self.env.company_id.currency_id.id)] + [('currency_id', '=', self.env.company.currency_id.id)] ).unlink() new_uom = self.env['uom.uom'].create({ 'name': '10 units', diff --git a/addons/sale/tests/test_sale_product_attribute_value_config.py b/addons/sale/tests/test_sale_product_attribute_value_config.py index 5b95765dfb2..792e3f8f3d6 100644 --- a/addons/sale/tests/test_sale_product_attribute_value_config.py +++ b/addons/sale/tests/test_sale_product_attribute_value_config.py @@ -25,7 +25,7 @@ class TestSaleProductAttributeValueSetup(TestProductAttributeValueSetup): non-reliant on demo data.""" name = fields.Date.today() currency_id = currency.id - company_id = self.env.company_id.id + company_id = self.env.company.id CurrencyRate = self.env['res.currency.rate'] diff --git a/addons/sale/wizard/payment_acquirer_onboarding_wizard.py b/addons/sale/wizard/payment_acquirer_onboarding_wizard.py index 1042c734977..96c7d66798f 100644 --- a/addons/sale/wizard/payment_acquirer_onboarding_wizard.py +++ b/addons/sale/wizard/payment_acquirer_onboarding_wizard.py @@ -12,7 +12,7 @@ class PaymentWizard(models.TransientModel): _description = 'Sale Payment acquire onboarding wizard' def _get_default_payment_method(self): - return self.env.company_id.sale_onboarding_payment_method or 'digital_signature' + return self.env.company.sale_onboarding_payment_method or 'digital_signature' payment_method = fields.Selection([ ('digital_signature', 'Online signature'), @@ -25,7 +25,7 @@ class PaymentWizard(models.TransientModel): def _set_payment_acquirer_onboarding_step_done(self): """ Override. """ - self.env.company_id.set_onboarding_step_done('sale_onboarding_order_confirmation_state') + self.env.company.set_onboarding_step_done('sale_onboarding_order_confirmation_state') def _on_save_payment_acquirer(self, *args, **kwargs): """ Override """ @@ -34,10 +34,10 @@ class PaymentWizard(models.TransientModel): @api.multi def add_payment_methods(self, *args, **kwargs): - self.env.company_id.sale_onboarding_payment_method = self.payment_method + self.env.company.sale_onboarding_payment_method = self.payment_method if self.payment_method == 'digital_signature': - self.env.company_id.portal_confirmation_sign = True + self.env.company.portal_confirmation_sign = True if self.payment_method in ('paypal', 'stripe', 'manual'): - self.env.company_id.portal_confirmation_pay = True + self.env.company.portal_confirmation_pay = True return super(PaymentWizard, self).add_payment_methods(*args, **kwargs) diff --git a/addons/sale_coupon/models/sale_coupon_program.py b/addons/sale_coupon/models/sale_coupon_program.py index d7294a23e46..f306954073b 100644 --- a/addons/sale_coupon/models/sale_coupon_program.py +++ b/addons/sale_coupon/models/sale_coupon_program.py @@ -48,7 +48,7 @@ class SaleCouponProgram(models.Model): coupon_count = fields.Integer(compute='_compute_coupon_count') order_count = fields.Integer(compute='_compute_order_count') order_line_ids = fields.Many2many('sale.order.line', store=False, search='_search_order_line_ids') - company_id = fields.Many2one('res.company', string="Company", default=lambda self: self.env.company_id) + company_id = fields.Many2one('res.company', string="Company", default=lambda self: self.env.company) currency_id = fields.Many2one(string="Currency", related='company_id.currency_id', readonly=True) validity_duration = fields.Integer(default=1, help="Validity duration for a coupon after its generation") diff --git a/addons/sale_crm/models/crm_lead.py b/addons/sale_crm/models/crm_lead.py index 11d5e6fdd4f..45f0982d0a0 100644 --- a/addons/sale_crm/models/crm_lead.py +++ b/addons/sale_crm/models/crm_lead.py @@ -20,7 +20,7 @@ class CrmLead(models.Model): total = 0.0 quotation_cnt = 0 sale_order_cnt = 0 - company_currency = lead.company_currency or self.env.company_id.currency_id + company_currency = lead.company_currency or self.env.company.currency_id for order in lead.order_ids: if order.state in ('draft', 'sent'): quotation_cnt += 1 diff --git a/addons/sale_management/models/sale_order_template.py b/addons/sale_management/models/sale_order_template.py index 8d1dc596d01..1cf3ecf6abf 100644 --- a/addons/sale_management/models/sale_order_template.py +++ b/addons/sale_management/models/sale_order_template.py @@ -11,10 +11,10 @@ class SaleOrderTemplate(models.Model): _description = "Quotation Template" def _get_default_require_signature(self): - return self.env.company_id.portal_confirmation_sign + return self.env.company.portal_confirmation_sign def _get_default_require_payment(self): - return self.env.company_id.portal_confirmation_pay + return self.env.company.portal_confirmation_pay name = fields.Char('Quotation Template', required=True) sale_order_template_line_ids = fields.One2many('sale.order.template.line', 'sale_order_template_id', 'Lines', copy=True) diff --git a/addons/sale_margin/models/sale_order.py b/addons/sale_margin/models/sale_order.py index 47e7bee47c8..ae0515d7bf2 100644 --- a/addons/sale_margin/models/sale_order.py +++ b/addons/sale_margin/models/sale_order.py @@ -12,7 +12,7 @@ class SaleOrderLine(models.Model): purchase_price = fields.Float(string='Cost', digits=dp.get_precision('Product Price')) def _compute_margin(self, order_id, product_id, product_uom_id): - frm_cur = self.env.company_id.currency_id + frm_cur = self.env.company.currency_id to_cur = order_id.pricelist_id.currency_id purchase_price = product_id.standard_price if product_uom_id != product_id.uom_id: @@ -23,14 +23,14 @@ class SaleOrderLine(models.Model): @api.model def _get_purchase_price(self, pricelist, product, product_uom, date): - frm_cur = self.env.company_id.currency_id + frm_cur = self.env.company.currency_id to_cur = pricelist.currency_id purchase_price = product.standard_price if product_uom != product.uom_id: purchase_price = product.uom_id._compute_price(purchase_price, product_uom) price = frm_cur._convert( purchase_price, to_cur, - self.order_id.company_id or self.env.company_id, + self.order_id.company_id or self.env.company, date or fields.Date.today(), round=False) return {'purchase_price': price} diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index 4b06daeac78..a055090c590 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -192,7 +192,7 @@ class SaleOrderLine(models.Model): 'partner_id': partner_supplier.id, 'partner_ref': partner_supplier.ref, 'company_id': self.company_id.id, - 'currency_id': partner_supplier.property_purchase_currency_id.id or self.env.company_id.currency_id.id, + 'currency_id': partner_supplier.property_purchase_currency_id.id or self.env.company.currency_id.id, 'dest_address_id': self.order_id.partner_shipping_id.id, 'origin': self.order_id.name, 'payment_term_id': partner_supplier.property_supplier_payment_term_id.id, diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 94b225ae84b..3d6b67ae58d 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -13,7 +13,7 @@ class SaleOrder(models.Model): @api.model def _default_warehouse_id(self): - company = self.env.company_id.id + company = self.env.company.id warehouse_ids = self.env['stock.warehouse'].search([('company_id', '=', company)], limit=1) return warehouse_ids diff --git a/addons/sale_timesheet/models/project_overview.py b/addons/sale_timesheet/models/project_overview.py index b68bc998f95..bd6d277a9df 100644 --- a/addons/sale_timesheet/models/project_overview.py +++ b/addons/sale_timesheet/models/project_overview.py @@ -26,7 +26,7 @@ class Project(models.Model): return values def _plan_prepare_values(self): - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id uom_hour = self.env.ref('uom.product_uom_hour') hour_rounding = uom_hour.rounding billable_types = ['non_billable', 'non_billable_project', 'billable_time', 'billable_fixed'] diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 66600ea170b..ee49687a9d2 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -221,7 +221,7 @@ class SaleOrderLine(models.Model): ########################################### def _convert_qty_company_hours(self): - company_time_uom_id = self.env.company_id.project_time_mode_id + company_time_uom_id = self.env.company.project_time_mode_id if self.product_uom.id != company_time_uom_id.id and self.product_uom.category_id.id == company_time_uom_id.category_id.id: planned_hours = self.product_uom._compute_quantity(self.product_uom_qty, company_time_uom_id) else: diff --git a/addons/sale_timesheet/tests/test_reporting.py b/addons/sale_timesheet/tests/test_reporting.py index bf9eb378c9c..a26042ec00e 100644 --- a/addons/sale_timesheet/tests/test_reporting.py +++ b/addons/sale_timesheet/tests/test_reporting.py @@ -121,7 +121,7 @@ class TestReporting(TestCommonSaleTimesheetNoChart): def test_profitability_report(self): # this test suppose everything is in the same currency as the current one - currency = self.env.company_id.currency_id + currency = self.env.company.currency_id rounding = currency.rounding project_global_stat = self.env['project.profitability.report'].search([('project_id', '=', self.project_global.id)]).read()[0] diff --git a/addons/sales_team/models/crm_team.py b/addons/sales_team/models/crm_team.py index 80016cfc24d..e7d2c1b0a15 100644 --- a/addons/sales_team/models/crm_team.py +++ b/addons/sales_team/models/crm_team.py @@ -26,7 +26,7 @@ class CrmTeam(models.Model): user_id = self.env.uid team_id = self.env['crm.team'].sudo().search([ '|', ('user_id', '=', user_id), ('member_ids', '=', user_id), - '|', ('company_id', '=', False), ('company_id', '=', self.env.company_id.id) + '|', ('company_id', '=', False), ('company_id', '=', self.env.company.id) ], limit=1) if not team_id and 'default_team_id' in self.env.context: team_id = self.env['crm.team'].browse(self.env.context.get('default_team_id')) @@ -48,7 +48,7 @@ class CrmTeam(models.Model): name = fields.Char('Sales Team', required=True, translate=True) active = fields.Boolean(default=True, help="If the active field is set to false, it will allow you to hide the Sales Team without removing it.") company_id = fields.Many2one('res.company', string='Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) currency_id = fields.Many2one( "res.currency", related='company_id.currency_id', string="Currency", readonly=True) diff --git a/addons/sms/wizard/send_sms.py b/addons/sms/wizard/send_sms.py index ba6c709fcdf..ac2d63a0d75 100644 --- a/addons/sms/wizard/send_sms.py +++ b/addons/sms/wizard/send_sms.py @@ -32,7 +32,7 @@ class SendSMS(models.TransientModel): def _phone_get_country(self, partner): if 'country_id' in partner: return partner.country_id - return self.env.company_id.country_id + return self.env.company.country_id def _sms_sanitization(self, partner, field_name): number = partner[field_name] diff --git a/addons/snailmail/models/snailmail_letter.py b/addons/snailmail/models/snailmail_letter.py index 5fd49dd892c..797bf92a0b0 100644 --- a/addons/snailmail/models/snailmail_letter.py +++ b/addons/snailmail/models/snailmail_letter.py @@ -32,15 +32,15 @@ class SnailmailLetter(models.Model): res_id = fields.Integer('Document ID', required=True) partner_id = fields.Many2one('res.partner', string='Recipient', required=True) company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, - default=lambda self: self.env.company_id.id) + default=lambda self: self.env.company.id) report_template = fields.Many2one('ir.actions.report', 'Optional report to print and attach') attachment_id = fields.Many2one('ir.attachment', string='Attachment', ondelete='cascade') attachment_datas = fields.Binary('Document', related='attachment_id.datas') attachment_fname = fields.Char('Attachment Filename', related='attachment_id.datas_fname') - color = fields.Boolean(string='Color', default=lambda self: self.env.company_id.snailmail_color) - cover = fields.Boolean(string='Cover Page', default=lambda self: self.env.company_id.snailmail_cover) - duplex = fields.Boolean(string='Both side', default=lambda self: self.env.company_id.snailmail_duplex) + color = fields.Boolean(string='Color', default=lambda self: self.env.company.snailmail_color) + cover = fields.Boolean(string='Cover Page', default=lambda self: self.env.company.snailmail_cover) + duplex = fields.Boolean(string='Both side', default=lambda self: self.env.company.snailmail_duplex) state = fields.Selection([ ('pending', 'In Queue'), ('sent', 'Sent'), @@ -402,8 +402,8 @@ class SnailmailLetter(models.Model): 'account_token': "", 'documents': doc_list, 'options': { - 'color': self.env.company_id.snailmail_color, - 'duplex': self.env.company_id.snailmail_duplex, + 'color': self.env.company.snailmail_color, + 'duplex': self.env.company.snailmail_duplex, 'currency_name': 'EUR', }, } diff --git a/addons/snailmail/wizard/snailmail_letter_format_error.py b/addons/snailmail/wizard/snailmail_letter_format_error.py index 37390cbe78b..0f830dd4ce6 100644 --- a/addons/snailmail/wizard/snailmail_letter_format_error.py +++ b/addons/snailmail/wizard/snailmail_letter_format_error.py @@ -11,7 +11,7 @@ class SnailmailLetterFormatError(models.TransientModel): @api.model def default_get(self, fields): res = super(SnailmailLetterFormatError, self).default_get(fields) - snailmail_cover = self.env.company_id.snailmail_cover + snailmail_cover = self.env.company.snailmail_cover res.update({ 'message_id': self.env.context.get('message_id'), 'snailmail_cover': snailmail_cover, @@ -20,7 +20,7 @@ class SnailmailLetterFormatError(models.TransientModel): @api.multi def update_resend_action(self): - self.env.company_id.write({'snailmail_cover': self.snailmail_cover}) + self.env.company.write({'snailmail_cover': self.snailmail_cover}) letters_to_resend = self.env['snailmail.letter'].search([ ('error_code', '=', 'FORMAT_ERROR'), ]) diff --git a/addons/snailmail_account/wizard/account_invoice_send.py b/addons/snailmail_account/wizard/account_invoice_send.py index 24461afc19d..d1545d808c4 100644 --- a/addons/snailmail_account/wizard/account_invoice_send.py +++ b/addons/snailmail_account/wizard/account_invoice_send.py @@ -11,7 +11,7 @@ class AccountInvoiceSend(models.TransientModel): _description = 'Account Invoice Send' partner_id = fields.Many2one('res.partner', compute='_get_partner', string='Partner') - snailmail_is_letter = fields.Boolean('Send by Post', help='Allows to send the document by Snailmail (coventional posting delivery service)', default=lambda self: self.env.company_id.invoice_is_snailmail) + snailmail_is_letter = fields.Boolean('Send by Post', help='Allows to send the document by Snailmail (coventional posting delivery service)', default=lambda self: self.env.company.invoice_is_snailmail) snailmail_cost = fields.Float(string='Stamp(s)', compute='_compute_snailmail_cost', readonly=True) invalid_addresses = fields.Integer('Invalid Addresses Count', compute='_compute_invalid_addresses') invalid_invoice_ids = fields.Many2many('account.invoice', string='Invalid Addresses', compute='_compute_invalid_addresses') diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 9daa9826979..5186f5d4e2d 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -174,7 +174,7 @@ class Product(models.Model): Warehouse = self.env['stock.warehouse'] if self.env.context.get('company_owned', False): - company_id = self.env.company_id.id + company_id = self.env.company.id return ( [('location_id.company_id', '=', company_id), ('location_id.usage', 'in', ['internal', 'transit'])], [('location_id.company_id', '=', False), ('location_dest_id.company_id', '=', company_id)], diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index 547f2f1858d..42d1b415085 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -14,7 +14,7 @@ class Inventory(models.Model): @api.model def _default_location_id(self): - company_user = self.env.company_id + company_user = self.env.company warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) if warehouse: return warehouse.lot_stock_id.id @@ -49,7 +49,7 @@ class Inventory(models.Model): 'res.company', 'Company', readonly=True, index=True, required=True, states={'draft': [('readonly', False)]}, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) location_id = fields.Many2one( 'stock.location', 'Inventoried Location', readonly=True, required=True, diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index 628f252f5e1..e1a1968c2bd 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -55,7 +55,7 @@ class Location(models.Model): parent_path = fields.Char(index=True) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, index=True, + default=lambda self: self.env.company, index=True, help='Let this field empty if this location is shared between companies') scrap_location = fields.Boolean('Is a Scrap Location?', default=False, help='Check this box to allow using this location to put scrapped/damaged goods.') return_location = fields.Boolean('Is a Return Location?', help='Check this box to allow using this location as a return location.') @@ -191,7 +191,7 @@ class Route(models.Model): supplier_wh_id = fields.Many2one('stock.warehouse', 'Supplying Warehouse') company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, index=True, + default=lambda self: self.env.company, index=True, help='Leave this field empty if this route is shared between all companies') product_ids = fields.Many2many('product.template', 'stock_route_product', 'route_id', 'product_id', 'Products', copy=False) categ_ids = fields.Many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories', copy=False) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 1ab2d251092..00d5ea57ea5 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -36,7 +36,7 @@ class StockMove(models.Model): help="Move date: scheduled date until move is done, then date of actual move processing") company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, index=True, required=True) date_expected = fields.Datetime( 'Expected Date', default=fields.Datetime.now, index=True, required=True, diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 0d8ac551c58..5c48553d49c 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -41,7 +41,7 @@ class PickingType(models.Model): show_entire_packs = fields.Boolean('Move Entire Packages', help="If ticked, you will be able to select entire packages to move") warehouse_id = fields.Many2one( 'stock.warehouse', 'Warehouse', ondelete='cascade', - default=lambda self: self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1)) + default=lambda self: self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)) active = fields.Boolean('Active', default=True) use_create_lots = fields.Boolean( 'Create New Lots/Serial Numbers', default=True, @@ -260,7 +260,7 @@ class Picking(models.Model): states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}) company_id = fields.Many2one( 'res.company', 'Company', - default=lambda self: self.env.company_id, + default=lambda self: self.env.company, index=True, required=True, states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}) user_id = fields.Many2one( diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 4cfaccd96f3..ad1926eb134 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -368,7 +368,7 @@ class QuantPackage(models.Model): @api.depends('quant_ids.package_id', 'quant_ids.location_id', 'quant_ids.company_id', 'quant_ids.owner_id', 'quant_ids.quantity', 'quant_ids.reserved_quantity') def _compute_package_info(self): for package in self: - values = {'location_id': False, 'company_id': self.env.company_id.id, 'owner_id': False} + values = {'location_id': False, 'company_id': self.env.company.id, 'owner_id': False} if package.quant_ids: values['location_id'] = package.quant_ids[0].location_id if all(q.owner_id == package.quant_ids[0].owner_id for q in package.quant_ids): diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index b013607f7e2..11bfa91a442 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -38,7 +38,7 @@ class StockRule(models.Model): required=True) sequence = fields.Integer('Sequence', default=20) company_id = fields.Many2one('res.company', 'Company', - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) location_id = fields.Many2one('stock.location', 'Destination Location', required=True) location_src_id = fields.Many2one('stock.location', 'Source Location') route_id = fields.Many2one('stock.location.route', 'Route', required=True, ondelete='cascade') @@ -337,7 +337,7 @@ class ProcurementGroup(models.Model): actions_to_run = defaultdict(list) errors = [] for procurement in procurements: - procurement.values.setdefault('company_id', self.env.company_id) + procurement.values.setdefault('company_id', self.env.company) procurement.values.setdefault('priority', '1') procurement.values.setdefault('date_planned', fields.Datetime.now()) rule = self._get_rule(procurement.product_id, procurement.location_id, procurement.values) @@ -485,7 +485,7 @@ class ProcurementGroup(models.Model): 1000 orderpoints. This is appropriate for batch jobs only. """ - if company_id and self.env.company_id.id != company_id: + if company_id and self.env.company.id != company_id: # To ensure that the company_id is taken into account for # all the processes triggered by this method # i.e. If a PO is generated by the run of the procurements the diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py index 4c83e54270d..8b52afbed5e 100644 --- a/addons/stock/models/stock_scrap.py +++ b/addons/stock/models/stock_scrap.py @@ -12,10 +12,10 @@ class StockScrap(models.Model): _description = 'Scrap' def _get_default_scrap_location_id(self): - return self.env['stock.location'].search([('scrap_location', '=', True), ('company_id', 'in', [self.env.company_id.id, False])], limit=1).id + return self.env['stock.location'].search([('scrap_location', '=', True), ('company_id', 'in', [self.env.company.id, False])], limit=1).id def _get_default_location_id(self): - company_user = self.env.company_id + company_user = self.env.company warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) if warehouse: return warehouse.lot_stock_id.id diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 6bd76ec7a2d..4f694566f07 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -22,10 +22,10 @@ class Warehouse(models.Model): # namedtuple used in helper methods generating values for routes Routing = namedtuple('Routing', ['from_loc', 'dest_loc', 'picking_type', 'action']) - name = fields.Char('Warehouse', index=True, required=True, default=lambda self: self.env.company_id.name) + name = fields.Char('Warehouse', index=True, required=True, default=lambda self: self.env.company.name) active = fields.Boolean('Active', default=True) company_id = fields.Many2one( - 'res.company', 'Company', default=lambda self: self.env.company_id, + 'res.company', 'Company', default=lambda self: self.env.company, index=True, readonly=True, required=True, help='The company is automatically set from your user preferences.') partner_id = fields.Many2one('res.partner', 'Address') @@ -241,7 +241,7 @@ class Warehouse(models.Model): transit_loc = ResCompany.browse(company_id).internal_transit_location_id.id self.env['res.partner'].browse(partner_id).with_context(force_company=company_id).write({'property_stock_customer': transit_loc, 'property_stock_supplier': transit_loc}) else: - transit_loc = self.env.company_id.internal_transit_location_id.id + transit_loc = self.env.company.internal_transit_location_id.id self.env['res.partner'].browse(partner_id).write({'property_stock_customer': transit_loc, 'property_stock_supplier': transit_loc}) def _create_or_update_sequences_and_picking_types(self): @@ -966,7 +966,7 @@ class Orderpoint(models.Model): help="Moves created through this orderpoint will be put in this procurement group. If none is given, the moves generated by stock rules will be grouped into one big picking.") company_id = fields.Many2one( 'res.company', 'Company', required=True, - default=lambda self: self.env.company_id) + default=lambda self: self.env.company) lead_days = fields.Integer( 'Lead Time', default=1, help="Number of days after the orderpoint is triggered to receive the products or to order to the vendor") diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 59de4393efa..76a156d14ba 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -15,7 +15,7 @@ class StockMove(SavepointCase): cls.pack_location = cls.env.ref('stock.location_pack_zone') cls.pack_location.active = True cls.transit_location = cls.env['stock.location'].search([ - ('company_id', '=', cls.env.company_id.id), + ('company_id', '=', cls.env.company.id), ('usage', '=', 'transit'), ], limit=1) cls.uom_unit = cls.env.ref('uom.product_uom_unit') diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 1ada2f45dbd..cb97d657e5c 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -2030,7 +2030,7 @@ class TestRoutes(TestStockCommon): 'name': 'create a move to push location', 'location_src_id': stock_location.id, 'location_id': push_location.id, - 'company_id': self.env.company_id.id, + 'company_id': self.env.company.id, 'action': 'push', 'auto': 'manual', 'picking_type_id': self.env.ref('stock.picking_type_in').id, diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 37cbcaaf605..1b0aef059b5 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -1857,11 +1857,11 @@ class TestStockFlow(TestStockCommon): # Need to add a new company on user. self.env.user.write({'company_ids': [(4, company_2.id)]}) - warehouse_company_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1) + warehouse_company_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) f = Form(self.env['stock.location.route']) f.name = 'From Company 1 to InterCompany' - f.company_id = self.env.company_id + f.company_id = self.env.company with f.rule_ids.new() as rule: rule.name = 'From Company 1 to InterCompany' rule.action = 'pull' @@ -1898,8 +1898,8 @@ class TestStockFlow(TestStockCommon): incoming_picking = self.env['stock.picking'].search([('product_id', '=', product.id), ('picking_type_id', '=', warehouse_company_1.in_type_id.id)]) outgoing_picking = self.env['stock.picking'].search([('product_id', '=', product.id), ('picking_type_id', '=', warehouse_company_2.out_type_id.id)]) - self.assertEqual(incoming_picking.company_id, self.env.company_id) - self.assertEqual(incoming_picking.move_lines.company_id, self.env.company_id) + self.assertEqual(incoming_picking.company_id, self.env.company) + self.assertEqual(incoming_picking.move_lines.company_id, self.env.company) self.assertEqual(outgoing_picking.company_id, company_2) self.assertEqual(outgoing_picking.move_lines.company_id, company_2) @@ -1921,11 +1921,11 @@ class TestStockFlow(TestStockCommon): # Need to add a new company on user. self.env.user.write({'company_ids': [(4, company_2.id)]}) - warehouse_company_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.company_id.id)], limit=1) + warehouse_company_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) f = Form(self.env['stock.location.route']) f.name = 'From Company 1 to InterCompany' - f.company_id = self.env.company_id + f.company_id = self.env.company with f.rule_ids.new() as rule: rule.name = 'From Company 1 to InterCompany' rule.action = 'pull' @@ -1990,15 +1990,15 @@ class TestStockFlow(TestStockCommon): incoming_picking = self.env['stock.picking'].search([('product_id', '=', product_from_company_2.id), ('picking_type_id', '=', warehouse_company_1.in_type_id.id)]) outgoing_picking = self.env['stock.picking'].search([('product_id', '=', product_from_company_2.id), ('picking_type_id', '=', warehouse_company_2.out_type_id.id)]) - self.assertEqual(incoming_picking.company_id, self.env.company_id) - self.assertEqual(incoming_picking.move_lines.mapped('company_id'), self.env.company_id) + self.assertEqual(incoming_picking.company_id, self.env.company) + self.assertEqual(incoming_picking.move_lines.mapped('company_id'), self.env.company) self.assertEqual(outgoing_picking.company_id, company_2) self.assertEqual(outgoing_picking.move_lines.company_id, company_2) incoming_picking = self.env['stock.picking'].search([('product_id', '=', product_from_company_3.id), ('picking_type_id', '=', warehouse_company_1.in_type_id.id)]) outgoing_picking = self.env['stock.picking'].search([('product_id', '=', product_from_company_3.id), ('picking_type_id', '=', warehouse_company_3.out_type_id.id)]) - self.assertEqual(incoming_picking.company_id, self.env.company_id) - self.assertEqual(incoming_picking.move_lines.mapped('company_id'), self.env.company_id) + self.assertEqual(incoming_picking.company_id, self.env.company) + self.assertEqual(incoming_picking.move_lines.mapped('company_id'), self.env.company) self.assertEqual(outgoing_picking.company_id, company_3) self.assertEqual(outgoing_picking.move_lines.company_id, company_3) diff --git a/addons/stock/wizard/product_replenish.py b/addons/stock/wizard/product_replenish.py index 6ab0979ace8..a2ac3d0f209 100644 --- a/addons/stock/wizard/product_replenish.py +++ b/addons/stock/wizard/product_replenish.py @@ -25,7 +25,7 @@ class ProductReplenish(models.TransientModel): @api.model def default_get(self, fields): res = super(ProductReplenish, self).default_get(fields) - company_user = self.env.company_id + company_user = self.env.company warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) product_tmpl_id = False if 'product_id' in fields: diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py index 211d2004227..693c56067b2 100644 --- a/addons/stock/wizard/stock_change_product_qty.py +++ b/addons/stock/wizard/stock_change_product_qty.py @@ -24,7 +24,7 @@ class ProductChangeQuantity(models.TransientModel): def default_get(self, fields): res = super(ProductChangeQuantity, self).default_get(fields) if 'location_id' in fields and not res.get('location_id'): - company_user = self.env.company_id + company_user = self.env.company warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) if warehouse: res['location_id'] = warehouse.lot_stock_id.id diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 36cb3867ba5..8fb6a9ff916 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -67,7 +67,7 @@ class ProductProduct(models.Model): quant_locs = self.env['stock.quant'].sudo().read_group([('product_id', 'in', self.ids)], ['location_id'], ['location_id']) quant_loc_ids = [loc['location_id'][0] for loc in quant_locs] - locations = self.env['stock.location'].search([('usage', '=', 'internal'), ('company_id', '=', self.env.company_id.id), ('id', 'in', quant_loc_ids)]) + locations = self.env['stock.location'].search([('usage', '=', 'internal'), ('company_id', '=', self.env.company.id), ('id', 'in', quant_loc_ids)]) product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in self} @@ -131,7 +131,7 @@ class ProductProduct(models.Model): @api.multi def _compute_stock_value_currency(self): - currency_id = self.env.company_id.currency_id + currency_id = self.env.company.currency_id for product in self: product.stock_value_currency_id = currency_id @@ -149,7 +149,7 @@ class ProductProduct(models.Model): FROM account_move_line AS aml WHERE aml.product_id IN %%s AND aml.company_id=%%s %s GROUP BY aml.product_id, aml.account_id""" - params = (tuple(real_time_product_ids), self.env.company_id.id) + params = (tuple(real_time_product_ids), self.env.company.id) if to_date: query = query % ('AND aml.date <= %s',) params = params + (to_date,) @@ -192,7 +192,7 @@ class ProductProduct(models.Model): price_used = product.standard_price if to_date: price_used = product.get_history_price( - self.env.company_id.id, + self.env.company.id, date=to_date, ) product.stock_value = price_used * qty_available diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 7ee06791991..3700cfaafa1 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -166,8 +166,8 @@ class StockMove(models.Model): ('location_id.company_id', '=', False), '&', ('location_id.usage', 'in', ['inventory', 'production']), - ('location_id.company_id', '=', company_id or self.env.company_id.id), - ('location_dest_id.company_id', '=', company_id or self.env.company_id.id), + ('location_id.company_id', '=', company_id or self.env.company.id), + ('location_dest_id.company_id', '=', company_id or self.env.company.id), ] return domain @@ -190,15 +190,15 @@ class StockMove(models.Model): ('location_id.company_id', '=', False), '&', ('location_id.usage', 'in', ['inventory', 'production']), - ('location_id.company_id', '=', company_id or self.env.company_id.id), - ('location_dest_id.company_id', '=', company_id or self.env.company_id.id), + ('location_id.company_id', '=', company_id or self.env.company.id), + ('location_dest_id.company_id', '=', company_id or self.env.company.id), '&', - ('location_id.company_id', '=', company_id or self.env.company_id.id), + ('location_id.company_id', '=', company_id or self.env.company.id), '|', ('location_dest_id.company_id', '=', False), '&', ('location_dest_id.usage', '=', 'inventory'), - ('location_dest_id.company_id', '=', company_id or self.env.company_id.id), + ('location_dest_id.company_id', '=', company_id or self.env.company.id), ] return domain diff --git a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py index ca4aab2f749..0db00180504 100644 --- a/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py +++ b/addons/stock_account/tests/test_anglo_saxon_valuation_reconciliation_common.py @@ -53,7 +53,7 @@ class ValuationReconciliationTestCase(AccountingTestCase): def setUp(self): super(ValuationReconciliationTestCase, self).setUp() - self.company = self.env.company_id + self.company = self.env.company self.company.anglo_saxon_accounting = True self.currency_one = self.company.currency_id currency_two_name = 'USD' if self.currency_one.name != 'USD' else 'EUR' diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index 7dd2b71ad75..d3c4a9918e0 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -942,7 +942,7 @@ class TestStockValuation(SavepointCase): # send 10 units in our transit location, the valorisation should not be impacted transit_location = self.env['stock.location'].search([ - ('company_id', '=', self.env.company_id.id), + ('company_id', '=', self.env.company.id), ('usage', '=', 'transit'), ], limit=1) move8 = self.env['stock.move'].create({ diff --git a/addons/stock_dropshipping/tests/test_stockvaluation.py b/addons/stock_dropshipping/tests/test_stockvaluation.py index 14fcd02f69d..919c8c0352c 100644 --- a/addons/stock_dropshipping/tests/test_stockvaluation.py +++ b/addons/stock_dropshipping/tests/test_stockvaluation.py @@ -107,7 +107,7 @@ class TestStockValuation(AccountingTestCase): # Continental # ------------------------------------------------------------------------- def test_dropship_standard_perpetual_continental_ordered(self): - self.env.company_id.anglo_saxon_accounting = False + self.env.company.anglo_saxon_accounting = False self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -125,7 +125,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 4, all_amls) def test_dropship_standard_perpetual_continental_delivered(self): - self.env.company_id.anglo_saxon_accounting = False + self.env.company.anglo_saxon_accounting = False self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -143,7 +143,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 4, all_amls) def test_dropship_fifo_perpetual_continental_ordered(self): - self.env.company_id.anglo_saxon_accounting = False + self.env.company.anglo_saxon_accounting = False self.product1.product_tmpl_id.categ_id.proprty_cost_method = 'fifo' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -161,7 +161,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 4, all_amls) def test_dropship_fifo_perpetual_continental_delivered(self): - self.env.company_id.anglo_saxon_accounting = False + self.env.company.anglo_saxon_accounting = False self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.standard_price = 10 @@ -183,7 +183,7 @@ class TestStockValuation(AccountingTestCase): # Anglosaxon # ------------------------------------------------------------------------- def test_dropship_standard_perpetual_anglosaxon_ordered(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -206,7 +206,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 8, all_amls) def test_dropship_standard_perpetual_anglosaxon_delivered(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -229,7 +229,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 8, all_amls) def test_dropship_fifo_perpetual_anglosaxon_ordered(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -249,7 +249,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 8, all_amls) def test_dropship_fifo_perpetual_anglosaxon_delivered(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' @@ -269,7 +269,7 @@ class TestStockValuation(AccountingTestCase): self._check_results(expected_aml, 8, all_amls) def test_dropship_standard_perpetual_anglosaxon_ordered_return(self): - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard' self.product1.product_tmpl_id.standard_price = 10 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' diff --git a/addons/stock_landed_costs/models/stock_landed_cost.py b/addons/stock_landed_costs/models/stock_landed_cost.py index 7f21cfafa6c..1d513fdc746 100644 --- a/addons/stock_landed_costs/models/stock_landed_cost.py +++ b/addons/stock_landed_costs/models/stock_landed_cost.py @@ -128,7 +128,7 @@ class LandedCost(models.Model): def _check_sum(self): """ Check if each cost line its valuation lines sum to the correct amount and if the overall total amount is correct also """ - prec_digits = self.env.company_id.currency_id.decimal_places + prec_digits = self.env.company.currency_id.decimal_places for landed_cost in self: total_amount = sum(landed_cost.valuation_adjustment_lines.mapped('additional_landed_cost')) if not tools.float_compare(total_amount, landed_cost.amount_total, precision_digits=prec_digits) == 0: @@ -365,7 +365,7 @@ class AdjustmentLines(models.Model): AccountMoveLine.append([0, 0, credit_line]) # TDE FIXME: oh dear - if self.env.company_id.anglo_saxon_accounting: + if self.env.company.anglo_saxon_accounting: debit_line = dict(base_line, name=(self.name + ": " + str(qty_out) + _(' already out')), quantity=0, diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs.py b/addons/stock_landed_costs/tests/test_stock_landed_costs.py index 793b913dc59..c2ceedf8109 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs.py @@ -58,7 +58,7 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): picking_landed_cost_1 = self.env['stock.picking'].create(vals) # Confirm and assign picking - self.env.company_id.anglo_saxon_accounting = True + self.env.company.anglo_saxon_accounting = True picking_landed_cost_1.action_confirm() picking_landed_cost_1.action_assign() picking_landed_cost_1.move_lines.quantity_done = 5 diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py b/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py index 4a7ab6e6eff..3b762f49b34 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py @@ -48,7 +48,7 @@ class TestLandedCosts(TestStockLandedCostsCommon): 'location_dest_id': self.customer_location_id}) def test_00_landed_costs_on_incoming_shipment(self): - chart_of_accounts = self.env.company_id.chart_template_id + chart_of_accounts = self.env.company.chart_template_id generic_coa = self.env.ref('l10n_generic_coa.configurable_chart_template') if chart_of_accounts != generic_coa: raise unittest.SkipTest('Skip this test as it works only with %s (%s loaded)' % (generic_coa.name, chart_of_accounts.name)) @@ -101,7 +101,7 @@ class TestLandedCosts(TestStockLandedCostsCommon): self.assertEqual(account_entry['debit'], 430.0, 'Wrong Account Entry') def test_01_negative_landed_costs_on_incoming_shipment(self): - chart_of_accounts = self.env.company_id.chart_template_id + chart_of_accounts = self.env.company.chart_template_id generic_coa = self.env.ref('l10n_generic_coa.configurable_chart_template') if chart_of_accounts != generic_coa: raise unittest.SkipTest('Skip this test as it works only with %s (%s loaded)' % (generic_coa.name, chart_of_accounts.name)) diff --git a/addons/survey/wizard/survey_invite.py b/addons/survey/wizard/survey_invite.py index 557b3f7d119..df0ea3f1eed 100644 --- a/addons/survey/wizard/survey_invite.py +++ b/addons/survey/wizard/survey_invite.py @@ -227,7 +227,7 @@ class SurveyInvite(models.TransientModel): template_ctx = { 'message': self.env['mail.message'].sudo().new(dict(body=mail_values['body_html'], record_name=self.survey_id.title)), 'model_description': self.env['ir.model']._get('survey.survey').display_name, - 'company': self.env.company_id, + 'company': self.env.company, } body = template.render(template_ctx, engine='ir.qweb', minimal_qcontext=True) mail_values['body_html'] = self.env['mail.thread']._replace_local_links(body) diff --git a/addons/test_mail/tests/test_mail_channel.py b/addons/test_mail/tests/test_mail_channel.py index 9994fcf76a0..ca65c921232 100644 --- a/addons/test_mail/tests/test_mail_channel.py +++ b/addons/test_mail/tests/test_mail_channel.py @@ -248,7 +248,7 @@ class TestChannelModeration(common.Moderation): self._init_mock_build_email() self.channel_1.sudo(self.user_employee).send_guidelines() self.env['mail.mail'].process_email_queue() - self.assertEmails(False, self.partner_employee | self.partner_employee_2, email_from=self.env.company_id.catchall or self.env.company_id.email) + self.assertEmails(False, self.partner_employee | self.partner_employee_2, email_from=self.env.company.catchall or self.env.company.email) def test_send_guidelines_crash(self): with self.assertRaises(UserError): diff --git a/addons/test_mail/tests/test_mail_message.py b/addons/test_mail/tests/test_mail_message.py index eb11145423b..c13fe2626ca 100644 --- a/addons/test_mail/tests/test_mail_message.py +++ b/addons/test_mail/tests/test_mail_message.py @@ -62,7 +62,7 @@ class TestMessageValues(common.BaseFunctionalTest, common.MockEmails): msg = self.Message.create({}) self.assertIn('-private', msg.message_id.split('@')[0], 'mail_message: message_id for a void message should be a "private" one') - reply_to_name = self.env.company_id.name + reply_to_name = self.env.company.name reply_to_email = '%s@%s' % (alias_catchall, alias_domain) self.assertEqual(msg.reply_to, formataddr((reply_to_name, reply_to_email))) self.assertEqual(msg.email_from, formataddr((self.user_employee.name, self.user_employee.email))) @@ -89,7 +89,7 @@ class TestMessageValues(common.BaseFunctionalTest, common.MockEmails): 'res_id': self.alias_record.id }) self.assertIn('-openerp-%d-mail.test' % self.alias_record.id, msg.message_id.split('@')[0]) - reply_to_name = '%s %s' % (self.env.company_id.name, self.alias_record.name) + reply_to_name = '%s %s' % (self.env.company.name, self.alias_record.name) reply_to_email = '%s@%s' % (self.alias_record.alias_name, alias_domain) self.assertEqual(msg.reply_to, formataddr((reply_to_name, reply_to_email))) self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email)) @@ -105,7 +105,7 @@ class TestMessageValues(common.BaseFunctionalTest, common.MockEmails): 'res_id': self.alias_record.id }) self.assertIn('-openerp-%d-mail.test' % self.alias_record.id, msg.message_id.split('@')[0]) - reply_to_name = '%s %s' % (self.env.company_id.name, self.alias_record.name) + reply_to_name = '%s %s' % (self.env.company.name, self.alias_record.name) reply_to_email = '%s@%s' % (self.alias_record.alias_name, alias_domain) self.assertEqual(msg.reply_to, formataddr((reply_to_name, reply_to_email))) self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email)) @@ -452,4 +452,4 @@ class TestMessageModeration(common.Moderation): msg_emp_pending_c2 = self._create_new_message(self.channel_2.id, status='pending_moderation', author=self.partner_employee) self.env['mail.message']._notify_moderators() - self.assertEmails(False, self.partner_employee | self.partner_employee_2, subject='Message are pending moderation', email_from=self.env.company_id.catchall or self.env.company_id.email) + self.assertEmails(False, self.partner_employee | self.partner_employee_2, subject='Message are pending moderation', email_from=self.env.company.catchall or self.env.company.email) diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py index 2a48312b12e..86327c174d4 100644 --- a/addons/test_mail/tests/test_mail_template.py +++ b/addons/test_mail/tests/test_mail_template.py @@ -207,7 +207,7 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients): def test_create_partner_from_tracking_multicompany(self): company1 = self.env['res.company'].create({'name': 'company1'}) self.env.user.write({'company_ids': [(4, company1.id, False)]}) - self.assertNotEqual(self.env.company_id, company1) + self.assertNotEqual(self.env.company, company1) email_new_partner = "diamonds@rust.com" Partner = self.env['res.partner'] diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 2cdce3872b3..08ded3c4769 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -390,7 +390,7 @@ class TestHeavyMailPerformance(TransactionCase): self.env['mail.mail'].browse(mail_ids).send() self.assertEqual(mail.body_html, '<p>Test</p>') - self.assertEqual(mail.reply_to, formataddr(('%s %s' % (self.env.company_id.name, self.umbrella.name), 'test-alias@example.com'))) + self.assertEqual(mail.reply_to, formataddr(('%s %s' % (self.env.company.name, self.umbrella.name), 'test-alias@example.com'))) @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('__system__', 'emp') diff --git a/addons/web_settings_dashboard/controllers/main.py b/addons/web_settings_dashboard/controllers/main.py index e25a65d42b0..574f9e8fd21 100644 --- a/addons/web_settings_dashboard/controllers/main.py +++ b/addons/web_settings_dashboard/controllers/main.py @@ -77,7 +77,7 @@ class WebSettingsDashboard(http.Controller): 'demo_active': demo_active, }, 'company': { - 'company_id': request.env.company_id.id, - 'company_name': request.env.company_id.name + 'company_id': request.env.company.id, + 'company_name': request.env.company.name } } diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 65286d4c2d4..86fe802d4f2 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -18,7 +18,7 @@ class WebsiteBackend(http.Controller): 'system': has_group_system, 'website_designer': has_group_designer }, - 'currency': request.env.company_id.currency_id.id, + 'currency': request.env.company.currency_id.id, 'dashboards': { 'visits': {}, } diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index f7406cf562d..892916b2a96 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -339,7 +339,7 @@ class View(models.Model): for website in Website.search([]) if website != cur ] - cur_company = self.env.company_id + cur_company = self.env.company qcontext['multi_website_companies_current'] = {'company_id': cur_company.id, 'name': cur_company.name} qcontext['multi_website_companies'] = [ {'company_id': comp.id, 'name': comp.name} diff --git a/addons/website/models/res_config_settings.py b/addons/website/models/res_config_settings.py index f9ebc435f57..64850911c1b 100644 --- a/addons/website/models/res_config_settings.py +++ b/addons/website/models/res_config_settings.py @@ -10,7 +10,7 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' def _default_website(self): - return self.env['website'].search([('company_id', '=', self.env.company_id.id)], limit=1) + return self.env['website'].search([('company_id', '=', self.env.company.id)], limit=1) website_id = fields.Many2one('website', string="website", default=_default_website, ondelete='cascade') diff --git a/addons/website_gengo/controllers/main.py b/addons/website_gengo/controllers/main.py index 506ccf025f1..56eeec5ff5c 100644 --- a/addons/website_gengo/controllers/main.py +++ b/addons/website_gengo/controllers/main.py @@ -27,7 +27,7 @@ class WebsiteGengo(http.Controller): @http.route('/website/set_gengo_config', type='json', auth='user', website=True) def set_gengo_config(self, config): - request.env.company_id.write(config) + request.env.company.write(config) return True @http.route('/website/post_gengo_jobs', type='json', auth='user', website=True) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 6f92c035714..137f15b5782 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -403,7 +403,7 @@ class WebsiteSale(http.Controller): from_currency = order.company_id.currency_id to_currency = order.pricelist_id.currency_id compute_currency = lambda price: from_currency._convert( - price, to_currency, request.env.company_id, fields.Date.today()) + price, to_currency, request.env.company, fields.Date.today()) else: compute_currency = lambda price: price diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index d96477a4e83..d78a2851025 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -21,7 +21,7 @@ class ProductPricelist(models.Model): def _default_website(self): """ Find the first company's website, if there is one. """ - company_id = self.env.company_id.id + company_id = self.env.company.id if self._context.get('default_company_id'): company_id = self._context.get('default_company_id') diff --git a/addons/website_sale/models/res_company.py b/addons/website_sale/models/res_company.py index f8d571e78c1..d0bce9b1121 100644 --- a/addons/website_sale/models/res_company.py +++ b/addons/website_sale/models/res_company.py @@ -12,6 +12,6 @@ class ResCompany(models.Model): @api.model def action_open_website_sale_onboarding_payment_acquirer(self): """ Called by onboarding panel above the quotation list.""" - self.env.company_id.get_chart_of_accounts_or_fail() + self.env.company.get_chart_of_accounts_or_fail() action = self.env.ref('website_sale.action_open_website_sale_onboarding_payment_acquirer_wizard').read()[0] return action diff --git a/addons/website_sale/wizard/payment_acquirer_onboarding_wizard.py b/addons/website_sale/wizard/payment_acquirer_onboarding_wizard.py index 2d5a0de5154..4673811abae 100644 --- a/addons/website_sale/wizard/payment_acquirer_onboarding_wizard.py +++ b/addons/website_sale/wizard/payment_acquirer_onboarding_wizard.py @@ -10,4 +10,4 @@ class PaymentWizard(models.TransientModel): def _set_payment_acquirer_onboarding_step_done(self): """ Override. """ - self.env.company_id.set_onboarding_step_done('website_sale_onboarding_payment_acquirer_state') + self.env.company.set_onboarding_step_done('website_sale_onboarding_payment_acquirer_state') diff --git a/addons/website_slides/wizard/slide_channel_invite.py b/addons/website_slides/wizard/slide_channel_invite.py index 99cdf3ae55a..76330d0da10 100644 --- a/addons/website_slides/wizard/slide_channel_invite.py +++ b/addons/website_slides/wizard/slide_channel_invite.py @@ -123,7 +123,7 @@ class SlideChannelInvite(models.TransientModel): template_ctx = { 'message': self.env['mail.message'].sudo().new(dict(body=mail_values['body_html'], record_name=self.channel_id.name)), 'model_description': self.env['ir.model']._get('website_slides.slide_channel').display_name, - 'company': self.env.company_id, + 'company': self.env.company, } body = template.render(template_ctx, engine='ir.qweb', minimal_qcontext=True) mail_values['body_html'] = self.env['mail.thread']._replace_local_links(body) |
