[IMP] base: Contextualize the multi company
Purpose
=======
Allow the user to select the allowed companies for which he wants to see records
on top of selecting his current company.
It is confusing for users to see the records from the company he is connected to
and the records of the children companies.
Instead of using the hierarchy of companies to access records across companies,
the user can now select (from his set of allowed companies) the companies for
which he wants to access records.
/!\ This means that the user will interact with records from company A when in
company B.
Example: a SO has been created and confirmed in A. When in B, I create the
invoice from it.
Specifications
==============
1/ Deprecate the parent/children hierarchy on the res.company model. The fields are
kept on the res.company model to ensure the retro-compatibility, but won't be used
accross the standard code anymore. The only functional usage for this mechanism
was to allow to see records from several companies by creating a virtual parent
company, which will be possible with the new mechanism.
2/ By default, a user will only see the records of the company he is connected
to (or records without a company). (It is still editable by the user if needed).
For that, put this information in the user context, to allow having different
configurations on different browser tabs. Instead of having domains like
['|',
('company_id', '=', False),
('company_id', 'child_of', user.company_id.id)]
you'll have something like
['|',
('company_id', '=', False),
('company_id', 'in', company_ids)]
Note that the 'company_ids' is a value that is passed in the evaluation
context on the record rule, as we already have user, or time.
company_ids is a list of the ids of all the enabled companies in the
user's context.
3/ Out of the generic improvements brought by this task, this will illustrate
issues that could exist since several versions. For example, it should not be
possible to create a scrap order for the company A with a package of the company
B, or it should not be possible to create an invoice on the company A with
payment terms from the company B. Before the version 12.0, it was easy to
encounter this kind of issues as the admin was the SUPERUSER_ID. A positive side
effect of the fact that the SUPERUSER_ID has become an inactive user was to
make it more difficult to introduce mismatch on the records, but haven't solved
the issue, as it was still possible to do it with parent companies
configuration. Some of these issues have been fixed in this commit, but all the
business flows should be re-tested to check if an ir.rule should be introduced
(eg: a multi company rule for stock.quand.package), if the company of a record
is correctly transfered to another record created from the first record (eg:
From a SO, create an invoice and a payment, the company of the sales order
should be transfered on the invoice and the payment, even if the company of the
sales order is A and I'm logged into the company B with the company A enabled.
4/ Currently, if I click on a button on a notification email (example 'View
Task'), I face a traceback if I'm not logged into the company of the record.
Now, if you click on a button and if you have access to the record, the correct
company will be automatically set.
5/ If I display a kanban view with several records from several companies (and
an image), all the images should be displayed.
6/ Currently if you copy paste an url, this will crash if you're not in the
correct company. This won't be fixed because it's quite impossible to do it in
a clean way. This task brings a workaround. Copy/Paste -> Traceback -> Log into
the correct company, re-copy/paste -> Ok.
7/ 2 property methods have been added on the environment to retrieve the company
on which the user is logged in and the companies the user enabled, on a specific
tab.
That way, when creating a record, instead of doing
default=lambda self: self.env.user.company_id
do
default=lambda self: self.env.company_id
On the other hand, to retrieve the enabled companies, do
companies = self.env.company_ids
8/ Modify the Company Switcher widget to allow to log into another company
WITHOUT writing on the res.users (and thus bringing cache invalidation issues
and so on). Also allow to enable several companies and see records from several
companies, and independantly of the other browser's tabs.
9/ When focusing on a tab, save the current company configuration on the local
storage. That way, when doing 'CTRL+T' or a middle click, the context is
propagated to the new tab.
10/ Improve the error message in case of multi company access errors. Now, when
the user is in debug mode, display the related names of the records and the name
of the user who brings the issue.
11/ Remove the context erasing when writing on a res.users
This is probably coming from the migration to new API of the base module.
The context was not propagated at this moment, which was a common mistake at
that time. When migrating the module, probably by using the 'black box' method,
as the context was not propagated, it was erased on the new version. This is
now an issue because the context (i.e. the enabled companies) was erased when
writing on a res.users, leading to tracebacks.
See: https://github.com/odoo/odoo/commit/7eab8e26d3d46c53f4be924d6a34e80a66e74960#diff-4c2e738ee8f64f11806c889ea097b5e7R624
12/ Fix the crash manager on redirect warnings. The issue is the following
- Create an invoice on a company without a configured CoA.
- Set a partner
- On the onchange_partner_id, a redirect warning is raised to propose you
to configure a CoA
- Click on 'Go to the configuration panel'
- A generic warning says something like 'Do you want to discard your changes?'
- Click on yes, the page refreshes, but not on the redirect action.
Now, set correctly the action on the hash, and reload instead. The breadcrumb is
lost for example, but you reach the correct action at least.
13/ Introduce a res.group to enable/disable the multi company per tab
feature.
14/ To help the users to know which tab is in which company, add the
possibility to have a favicon per company. When creating a company,
the classical 'O' icon is colored by default in a random color.
15/ Remove the company switcher on the frontend. This was mainly there
to allow a user to swicth to the company linked to the website.
This behavior is now transparent to the user. If the website A is
activated, then the company set on the context is the company of the
website.
16/ Deprecated the _company_default_get method on the res.company
model. Remove the method _get_company on the res.users model.
17/ Add 'allowed_company_ids' and 'current_company_id' on the pyeval
context. You can now use those variables on domains in the views to
access directly to the activated company.ies on the current tab.
TaskID: 1960971
closes odoo/odoo#32341
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -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.user.company_id.country_id.code
|
||||
country_code = env.company_id.country_id.code
|
||||
if country_code:
|
||||
#auto install localization module(s) if available
|
||||
module_list = []
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = request.env.company_id
|
||||
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.user.company_id
|
||||
company = request.env.company_id
|
||||
|
||||
if not request.env.user._is_admin() or \
|
||||
company.account_dashboard_onboarding_state == 'closed':
|
||||
|
||||
@@ -91,7 +91,7 @@ class AccountAccount(models.Model):
|
||||
'account_id', 'tax_id', string='Default Taxes')
|
||||
note = fields.Text('Internal Notes')
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True,
|
||||
default=lambda self: self.env['res.company']._company_default_get('account.account'))
|
||||
default=lambda self: self.env.company_id)
|
||||
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')
|
||||
|
||||
@@ -390,7 +390,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['res.company']._company_default_get('account.account'))
|
||||
company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company_id)
|
||||
account_journal_ids = fields.Many2many('account.journal', string="Journals")
|
||||
sequence = fields.Integer(default=10)
|
||||
|
||||
@@ -457,7 +457,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.user.company_id,
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, index=True, default=lambda self: self.env.company_id,
|
||||
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)
|
||||
@@ -760,7 +760,7 @@ class AccountJournal(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
company_id = vals.get('company_id', self.env.user.company_id.id)
|
||||
company_id = vals.get('company_id', self.env.company_id.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:
|
||||
@@ -832,16 +832,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.user.company_id.id)
|
||||
journal.belong_to_company = (journal.company_id.id == self.env.company_id.id)
|
||||
|
||||
@api.multi
|
||||
def _search_company_journals(self, operator, value):
|
||||
if value:
|
||||
recs = self.search([('company_id', operator, self.env.user.company_id.id)])
|
||||
recs = self.search([('company_id', operator, self.env.company_id.id)])
|
||||
elif operator == '=':
|
||||
recs = self.search([('company_id', '!=', self.env.user.company_id.id)])
|
||||
recs = self.search([('company_id', '!=', self.env.company_id.id)])
|
||||
else:
|
||||
recs = self.search([('company_id', operator, self.env.user.company_id.id)])
|
||||
recs = self.search([('company_id', operator, self.env.company_id.id)])
|
||||
return [('id', 'in', [x.id for x in recs])]
|
||||
|
||||
@api.multi
|
||||
@@ -899,7 +899,7 @@ class AccountTax(models.Model):
|
||||
amount_type = fields.Selection(default='percent', string="Tax Computation", required=True, oldname='type',
|
||||
selection=[('group', 'Group of Taxes'), ('fixed', 'Fixed'), ('percent', 'Percentage of Price'), ('division', 'Percentage of Price Tax 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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id)
|
||||
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.")
|
||||
@@ -1080,7 +1080,7 @@ class AccountTax(models.Model):
|
||||
}]
|
||||
} """
|
||||
if len(self) == 0:
|
||||
company_id = self.env.user.company_id
|
||||
company_id = self.env.company_id
|
||||
else:
|
||||
company_id = self[0].company_id
|
||||
if not currency:
|
||||
|
||||
@@ -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['res.company']._company_default_get('account.bank.statement').id
|
||||
company_id = self.env.company_id.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['res.company']._company_default_get('account.bank.statement'))
|
||||
default=lambda self: self.env.company_id)
|
||||
|
||||
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')
|
||||
|
||||
@@ -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.user.company_id)
|
||||
default=lambda self: self.env.company_id)
|
||||
|
||||
@api.constrains('date_from', 'date_to', 'company_id')
|
||||
def _check_dates(self):
|
||||
|
||||
@@ -49,7 +49,7 @@ class AccountInvoice(models.Model):
|
||||
|
||||
|
||||
def _get_default_incoterm(self):
|
||||
return self.env.user.company_id.incoterm_id
|
||||
return self.env.company_id.incoterm_id
|
||||
|
||||
@api.one
|
||||
@api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'tax_line_ids.amount_rounding',
|
||||
@@ -82,7 +82,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.user.company_id.id)
|
||||
company_id = self._context.get('company_id', self.env.company_id.id)
|
||||
domain = [
|
||||
('type', 'in', [TYPE2JOURNAL[ty] for ty in inv_types if ty in TYPE2JOURNAL]),
|
||||
('company_id', '=', company_id),
|
||||
@@ -96,12 +96,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.user.company_id.currency_id
|
||||
return journal.currency_id or journal.company_id.currency_id or self.env.company_id.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.user.company_id.invoice_terms
|
||||
return self.env.company_id.invoice_terms
|
||||
|
||||
def _get_aml_for_amount_residual(self):
|
||||
""" Get the aml to consider to compute the amount residual of invoices """
|
||||
@@ -367,7 +367,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['res.company']._company_default_get('account.invoice'))
|
||||
default=lambda self: self.env.company_id)
|
||||
|
||||
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.")
|
||||
@@ -734,7 +734,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.user.company_id.set_onboarding_step_done('account_onboarding_sample_invoice_state')
|
||||
self.env.company_id.set_onboarding_step_done('account_onboarding_sample_invoice_state')
|
||||
return super(AccountInvoice, self.with_context(mail_post_autofollow=True)).message_post(**kwargs)
|
||||
|
||||
@api.model
|
||||
@@ -1746,7 +1746,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.user.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_id, 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
|
||||
|
||||
@@ -1848,7 +1848,7 @@ class AccountInvoiceLine(models.Model):
|
||||
taxes = self.product_id.supplier_taxes_id or self.account_id.tax_ids or self.invoice_id.company_id.account_purchase_tax_id
|
||||
|
||||
# Keep only taxes of the company
|
||||
company_id = self.company_id or self.env.user.company_id
|
||||
company_id = self.company_id or self.env.company_id
|
||||
taxes = taxes.filtered(lambda r: r.company_id == company_id)
|
||||
|
||||
self.invoice_line_tax_ids = fp_taxes = self.invoice_id.fiscal_position_id.map_tax(taxes, self.product_id, self.invoice_id.partner_id)
|
||||
|
||||
@@ -281,7 +281,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.user.company_id
|
||||
company = self.env['res.company'].browse(result.get('company_id')) or self.env.company_id
|
||||
rslt_count += 1
|
||||
date = result.get('date_invoice') or fields.Date.today()
|
||||
|
||||
|
||||
@@ -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.user.company_id.id)], limit=1).id})
|
||||
rec.update({'journal_id': self.env['account.journal'].search([('type', '=', 'general'), ('company_id', '=', self.env.company_id.id)], limit=1).id})
|
||||
return rec
|
||||
|
||||
@api.multi
|
||||
@@ -90,12 +90,12 @@ class AccountMove(models.Model):
|
||||
@api.one
|
||||
@api.depends('company_id')
|
||||
def _compute_currency(self):
|
||||
self.currency_id = self.company_id.currency_id or self.env.user.company_id.currency_id
|
||||
self.currency_id = self.company_id.currency_id or self.env.company_id.currency_id
|
||||
|
||||
@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.user.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.id), ('type', '=', self.env.context['default_journal_type'])], limit=1).id
|
||||
|
||||
@api.multi
|
||||
@api.depends('line_ids.partner_id')
|
||||
@@ -402,7 +402,7 @@ class AccountMove(models.Model):
|
||||
def assert_balanced(self):
|
||||
if not self.ids:
|
||||
return True
|
||||
prec = self.env.user.company_id.currency_id.decimal_places
|
||||
prec = self.env.company_id.currency_id.decimal_places
|
||||
|
||||
self._cr.execute("""\
|
||||
SELECT move_id
|
||||
@@ -484,7 +484,7 @@ class AccountMove(models.Model):
|
||||
('reverse_entry_id', '=', False)])
|
||||
for move in records:
|
||||
date = None
|
||||
if move.reverse_date and (not self.env.user.company_id.period_lock_date or move.reverse_date > self.env.user.company_id.period_lock_date):
|
||||
if move.reverse_date and (not self.env.company_id.period_lock_date or move.reverse_date > self.env.company_id.period_lock_date):
|
||||
date = move.reverse_date
|
||||
move.reverse_moves(date=date, auto=True)
|
||||
|
||||
@@ -1348,7 +1348,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.user.company_id
|
||||
company = self.env['res.company'].browse(company) if company else self.env.company_id
|
||||
if src_currency and src_currency != company_currency:
|
||||
amount_currency = amount
|
||||
amount = src_currency._convert(amount, company_currency, company, date)
|
||||
@@ -1404,7 +1404,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.user.company_id.id,
|
||||
'company_id': move_line.analytic_account_id.company_id.id or self.env.company_id.id,
|
||||
})
|
||||
return result
|
||||
|
||||
@@ -1429,7 +1429,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.user.company_id.id,
|
||||
'company_id': distribution.account_id.company_id.id or self.env.company_id.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -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.user.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_id.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'))])
|
||||
@@ -304,7 +304,7 @@ class account_payment(models.Model):
|
||||
if payment_currency == currency:
|
||||
total += amount_total
|
||||
else:
|
||||
total += payment_currency._convert(amount_total, currency, self.env.user.company_id, self.payment_date or fields.Date.today())
|
||||
total += payment_currency._convert(amount_total, currency, self.env.company_id, self.payment_date or fields.Date.today())
|
||||
return total
|
||||
|
||||
@api.multi
|
||||
@@ -693,7 +693,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.user.company_id.id), ('type', 'in', ('bank', 'cash'))], limit=1).id
|
||||
rec['journal_id'] = self.env['account.journal'].search([('company_id', '=', self.env.company_id.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')]
|
||||
|
||||
@@ -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.user.company_id.currency_id
|
||||
currency = self.env.company_id.currency_id
|
||||
for line in self.line_ids:
|
||||
if line.value == 'fixed':
|
||||
amt = sign * currency.round(line.value_amount)
|
||||
|
||||
@@ -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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id)
|
||||
|
||||
rule_type = fields.Selection(selection=[
|
||||
('writeoff_button', _('Manually create a write-off on clicked button.')),
|
||||
|
||||
@@ -165,13 +165,10 @@ class AccountChartTemplate(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
# do not use `request.env` here, it can cause deadlocks
|
||||
if request and request.session.uid:
|
||||
current_user = self.env['res.users'].browse(request.uid)
|
||||
company = current_user.company_id
|
||||
if request and 'allowed_company_ids' in dir(request):
|
||||
company = self.env['res.company'].browse(request.allowed_company_ids[0])
|
||||
else:
|
||||
# fallback to company of current user, most likely __system__
|
||||
# (won't work well for multi-company)
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
# If we don't have any chart of account on this company, install this chart of account
|
||||
if not company.chart_template_id and not self.existing_accounting(company):
|
||||
self.load_for_current_company(15.0, 15.0)
|
||||
@@ -186,13 +183,10 @@ class AccountChartTemplate(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
# do not use `request.env` here, it can cause deadlocks
|
||||
if request and request.session.uid:
|
||||
current_user = self.env['res.users'].browse(request.uid)
|
||||
company = current_user.company_id
|
||||
if request and 'allowed_company_ids' in dir(request):
|
||||
company = self.env['res.company'].browse(request.allowed_company_ids[0])
|
||||
else:
|
||||
# fallback to company of current user, most likely __system__
|
||||
# (won't work well for multi-company)
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
# Ensure everything is translated to the company's language, not the user's one.
|
||||
self = self.with_context(lang=company.partner_id.lang)
|
||||
if not self.env.user._is_admin():
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = self.env.company_id
|
||||
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.user.company_id
|
||||
company = self.env.company_id
|
||||
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.user.company_id.account_invoice_onboarding_state = 'closed'
|
||||
self.env.company_id.account_invoice_onboarding_state = 'closed'
|
||||
|
||||
@api.model
|
||||
def action_close_account_dashboard_onboarding(self):
|
||||
""" Mark the dashboard onboarding panel as closed. """
|
||||
self.env.user.company_id.account_dashboard_onboarding_state = 'closed'
|
||||
self.env.company_id.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.user.company_id.id
|
||||
action['res_id'] = self.env.company_id.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.user.company_id.id
|
||||
action['res_id'] = self.env.company_id.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.user.company_id.id
|
||||
company_id = self.env.company_id.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.user.company_id.get_chart_of_accounts_or_fail()
|
||||
account = self.env.company_id.get_chart_of_accounts_or_fail()
|
||||
|
||||
journal = self.env['account.journal'].search([('company_id', '=', company_id)], limit=1)
|
||||
if len(journal) == 0:
|
||||
|
||||
@@ -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.user.company_id.id)._query_get()
|
||||
tables, where_clause, where_params = self.env['account.move.line'].with_context(company_id=self.env.company_id.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.user.company_id.currency_id.id
|
||||
user_currency_id = self.env.company_id.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.user.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.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.user.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.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.user.company_id.currency_id
|
||||
self.currency_id = self.env.company_id.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.user.company_id
|
||||
company = self.env.company_id
|
||||
return {'domain': {'property_account_position_id': [('company_id', 'in', [company.id, False])]}}
|
||||
|
||||
def can_edit_vat(self):
|
||||
|
||||
@@ -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.user.company_id.account_sale_tax_id)
|
||||
domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company_id.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.user.company_id.account_purchase_tax_id)
|
||||
domain=[('type_tax_use', '=', 'purchase')], default=lambda self: self.env.company_id.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)],
|
||||
|
||||
@@ -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.user.company_id.id,
|
||||
self.env.company_id.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 ' ',
|
||||
|
||||
@@ -142,7 +142,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
def _onchange_tax_exigibility(self):
|
||||
res = {}
|
||||
tax = self.env['account.tax'].search([
|
||||
('company_id', '=', self.env.user.company_id.id), ('tax_exigibility', '=', 'on_payment')
|
||||
('company_id', '=', self.env.company_id.id), ('tax_exigibility', '=', 'on_payment')
|
||||
], limit=1)
|
||||
if not self.tax_exigibility and tax:
|
||||
self.tax_exigibility = True
|
||||
|
||||
@@ -46,7 +46,7 @@ class ReportAgedPartnerBalance(models.AbstractModel):
|
||||
total = []
|
||||
partner_clause = ''
|
||||
cr = self.env.cr
|
||||
user_company = self.env.user.company_id
|
||||
user_company = self.env.company_id
|
||||
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.user.company_id.currency_id.is_zero(line_amount):
|
||||
if not self.env.company_id.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.user.company_id.currency_id.is_zero(line_amount):
|
||||
if not self.env.company_id.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.user.company_id.currency_id.rounding):
|
||||
if not float_is_zero(values['direction'], precision_rounding=self.env.company_id.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.user.company_id.currency_id.rounding):
|
||||
if not float_is_zero(values[str(i)], precision_rounding=self.env.company_id.currency_id.rounding):
|
||||
at_least_one_amount = True
|
||||
values['total'] = sum([values['direction']] + [values[str(i)] for i in range(5)])
|
||||
## Add for total
|
||||
|
||||
@@ -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.user.company_id.currency_id
|
||||
user_currency_id = self.env.company_id.currency_id
|
||||
currency_rate_id = self.env['res.currency.rate'].search([
|
||||
('rate', '=', 1),
|
||||
'|', ('company_id', '=', self.env.user.company_id.id), ('company_id', '=', False)], limit=1)
|
||||
'|', ('company_id', '=', self.env.company_id.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()
|
||||
|
||||
@@ -86,104 +86,104 @@
|
||||
<field name="name">Account Entry</field>
|
||||
<field name="model_id" ref="model_account_move"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="account_move_line_comp_rule" model="ir.rule">
|
||||
<field name="name">Entry lines</field>
|
||||
<field name="model_id" ref="model_account_move_line"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="journal_comp_rule" model="ir.rule">
|
||||
<field name="name">Journal multi-company</field>
|
||||
<field name="model_id" ref="model_account_journal_group"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="journal_comp_rule" model="ir.rule">
|
||||
<field name="name">Journal multi-company</field>
|
||||
<field name="model_id" ref="model_account_journal"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="account_comp_rule" model="ir.rule">
|
||||
<field name="name">Account multi-company</field>
|
||||
<field name="model_id" ref="model_account_account"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="tax_comp_rule" model="ir.rule">
|
||||
<field name="name">Tax multi-company</field>
|
||||
<field name="model_id" ref="model_account_tax"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_comp_rule" model="ir.rule">
|
||||
<field name="name">Invoice multi-company</field>
|
||||
<field name="model_id" ref="model_account_invoice"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_analysis_comp_rule" model="ir.rule">
|
||||
<field name="name">Invoice Analysis multi-company</field>
|
||||
<field name="model_id" ref="model_account_invoice_report"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="account_fiscal_position_comp_rule" model="ir.rule">
|
||||
<field name="name">Account fiscal Mapping company rule</field>
|
||||
<field name="model_id" ref="model_account_fiscal_position"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_invoice_line_comp_rule">
|
||||
<field name="name">Invoice Line company rule</field>
|
||||
<field name="model_id" ref="model_account_invoice_line"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_bank_statement_comp_rule">
|
||||
<field name="name">Account bank statement company rule</field>
|
||||
<field name="model_id" ref="model_account_bank_statement"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_bank_statement_line_comp_rule">
|
||||
<field name="name">Account bank statement line company rule</field>
|
||||
<field name="model_id" ref="model_account_bank_statement_line"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_reconcile_model_template_comp_rule">
|
||||
<field name="name">Account reconcile model template company rule</field>
|
||||
<field name="model_id" ref="model_account_reconcile_model"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_payment_comp_rule">
|
||||
<field name="name">Account payment company rule</field>
|
||||
<field name="model_id" ref="model_account_payment"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="account_payment_term_comp_rule">
|
||||
<field name="name">Account payment term company rule</field>
|
||||
<field name="model_id" ref="model_account_payment_term"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<!-- Portal for invoice and invoice lines -->
|
||||
|
||||
@@ -27,7 +27,7 @@ class AccountingTestCase(HttpCase):
|
||||
|
||||
:param property_name: The name of the property.
|
||||
'''
|
||||
company_id = self.env.user.company_id
|
||||
company_id = self.env.company_id
|
||||
field_id = self.env['ir.model.fields'].search(
|
||||
[('model', '=', 'product.template'), ('name', '=', property_name)], limit=1)
|
||||
property_id = self.env['ir.property'].search([
|
||||
|
||||
@@ -40,5 +40,5 @@ class TestAllL10n(SingleTransactionCase):
|
||||
comp = self.env['res.company'].create({
|
||||
'name': cname,
|
||||
})
|
||||
self.env.user.company_id = comp
|
||||
self.env.company_id = comp
|
||||
coa.try_loading_for_current_company()
|
||||
|
||||
@@ -108,7 +108,7 @@ class TestAccountCustomerInvoice(AccountTestUsers):
|
||||
|
||||
def test_customer_invoice_tax(self):
|
||||
|
||||
self.env.user.company_id.tax_calculation_rounding_method = 'round_globally'
|
||||
self.env.company_id.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.assertEquals(invoice.amount_untaxed, sum([x.base for x in invoice.tax_line_ids]))
|
||||
|
||||
def test_customer_invoice_tax_refund(self):
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
tax_account = self.env['account.account'].create({
|
||||
'name': 'TAX',
|
||||
'code': 'TAX',
|
||||
|
||||
@@ -70,7 +70,7 @@ class TestBankStatementReconciliation(AccountingTestCase):
|
||||
vals = {'partner_id': self.partner.id,
|
||||
'type': 'out_invoice',
|
||||
'name': '-',
|
||||
'currency_id': self.env.user.company_id.currency_id.id,
|
||||
'currency_id': self.env.company_id.currency_id.id,
|
||||
}
|
||||
# new creates a temporary record to apply the on_change afterwards
|
||||
invoice = self.i_model.new(vals)
|
||||
|
||||
@@ -912,7 +912,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.user.company_id.currency_id
|
||||
currency = self.env.company_id.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'})
|
||||
@@ -1021,7 +1021,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.user.company_id.currency_id
|
||||
currency = self.env.company_id.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'})
|
||||
@@ -1523,7 +1523,7 @@ class TestReconciliationExec(TestReconciliation):
|
||||
|
||||
def test_reconciliation_to_check(self):
|
||||
partner = self.env['res.partner'].create({'name': 'UncertainPartner'})
|
||||
currency = self.env.user.company_id.currency_id
|
||||
currency = self.env.company_id.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})
|
||||
|
||||
|
||||
@@ -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.user.company_id.invoice_is_email)
|
||||
is_print = fields.Boolean('Print', default=lambda self: self.env.user.company_id.invoice_is_print)
|
||||
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)
|
||||
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')
|
||||
|
||||
@@ -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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id)
|
||||
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')
|
||||
|
||||
@@ -42,7 +42,7 @@ class FinancialYearOpeningWizard(models.TransientModel):
|
||||
|
||||
@api.multi
|
||||
def action_save_onboarding_fiscal_year(self):
|
||||
self.env.user.company_id.set_onboarding_step_done('account_setup_fy_data_state')
|
||||
self.env.company_id.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['res.company']._company_default_get('account.journal').id)
|
||||
record.new_journal_code = self.env['account.journal'].get_next_bank_cash_default_code('bank', self.env.company_id.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.user.company_id.partner_id.id
|
||||
vals['partner_id'] = self.env.company_id.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['res.company']._company_default_get('account.journal')
|
||||
company = self.env.company_id
|
||||
selected_journal = self.env['account.journal'].create({
|
||||
'name': record.new_journal_name,
|
||||
'code': record.new_journal_code,
|
||||
|
||||
@@ -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.user.company_id.currency_id)
|
||||
company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.company_id.currency_id)
|
||||
tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'adjustment')], required=True)
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<field name="name">Analytic Default multi company rule</field>
|
||||
<field name="model_id" ref="model_account_analytic_default"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -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.user.company_id.currency_id
|
||||
company_currency = self.env.company_id.currency_id
|
||||
journal_obj = self.env['account.journal']
|
||||
currency = None
|
||||
sanitized_account_number = sanitize_account_number(account_number)
|
||||
|
||||
@@ -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.user.company_id.currency_id and currency.active:
|
||||
if currency != self.env.company_id.currency_id and currency.active:
|
||||
invoice_form.currency_id = currency
|
||||
|
||||
# Store xml total amount.
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = self.env.company_id
|
||||
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):
|
||||
taxes = self.filtered(lambda r: r.amount_type != 'code')
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
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})
|
||||
|
||||
@@ -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.user.company_id.id)
|
||||
company_id = self._context.get('company_id', self.env.company_id.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.user.company_id.id)
|
||||
company_id = self._context.get('company_id', self.env.company_id.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.user.company_id.currency_id.id
|
||||
return self.env.company_id.currency_id.id
|
||||
|
||||
@api.model
|
||||
def _get_company(self):
|
||||
return self._context.get('company_id', self.env.user.company_id.id)
|
||||
return self._context.get('company_id', self.env.company_id.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.user.company_id.tax_calculation_rounding_method
|
||||
tax_calculation_rounding_method = self.env.company_id.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
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
<field name="name">Voucher multi-company</field>
|
||||
<field name="model_id" ref="model_account_voucher"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
<record id="voucher_line_comp_rule" model="ir.rule">
|
||||
<field name="name">Voucher Line multi-company</field>
|
||||
<field name="model_id" ref="model_account_voucher_line"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -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.user.company_id.currency_id
|
||||
user_currency = self.env.company_id.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.user.company_id, fields.Date.today())
|
||||
l['amount'], user_currency, self.env.company_id, 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.user.company_id, fields.Date.today())
|
||||
l['amount'], user_currency, self.env.company_id, 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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id)
|
||||
|
||||
# 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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company_id)
|
||||
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)
|
||||
|
||||
|
||||
@@ -6,28 +6,28 @@
|
||||
<field name="name">Analytic multi company rule</field>
|
||||
<field name="model_id" ref="model_account_analytic_account"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="analytic_line_comp_rule" model="ir.rule">
|
||||
<field name="name">Analytic line multi company rule</field>
|
||||
<field name="model_id" ref="model_account_analytic_line"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="analytic_group_comp_rule" model="ir.rule">
|
||||
<field name="name">Analytic line multi company rule</field>
|
||||
<field name="model_id" ref="model_account_analytic_group"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="analytic_tag_comp_rule" model="ir.rule">
|
||||
<field name="name">Analytic line multi company rule</field>
|
||||
<field name="model_id" ref="model_account_analytic_tag"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
</data>
|
||||
<data noupdate="0">
|
||||
|
||||
@@ -9,8 +9,9 @@ class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
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.user.company_id)
|
||||
default=lambda self: self.env.company_id)
|
||||
user_default_rights = fields.Boolean(
|
||||
"Default Access Rights",
|
||||
config_parameter='base_setup.default_user_rights',
|
||||
@@ -67,7 +68,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'res.company',
|
||||
'res_id': self.env.user.company_id.id,
|
||||
'res_id': self.env.company_id.id,
|
||||
'target': 'current',
|
||||
}
|
||||
@api.multi
|
||||
@@ -103,7 +104,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.env.user.company_id.id,
|
||||
'res_id': self.env.company_id.id,
|
||||
'res_model': 'res.company',
|
||||
'views': [(template.id, 'form')],
|
||||
'view_id': template.id,
|
||||
|
||||
@@ -141,6 +141,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="group_toggle_company"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label string="Multi-companies by Tab" for="group_toggle_company"/>
|
||||
<div class="text-muted">
|
||||
Manage multiple companies on the same browser tab. Be careful that this advanced tool should
|
||||
only be used for reporting purpose.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box" title="Configure company rules to automatically create SO/PO when one of your company sells/buys to another of your company." attrs="{'invisible': [('group_multi_company', '=', False)]}" id="inter_company">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="module_inter_company_rules" widget="upgrade_boolean"/>
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = self.env.company_id
|
||||
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.user.company_id
|
||||
company = self.env.company_id
|
||||
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)
|
||||
|
||||
@@ -124,7 +124,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.user.company_id.id)
|
||||
company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company_id.id)
|
||||
meeting_count = fields.Integer('# Meetings', compute='_compute_meeting_count')
|
||||
lost_reason = fields.Many2one('crm.lost.reason', string='Lost Reason', index=True, tracking=True)
|
||||
|
||||
@@ -1082,7 +1082,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.user.company_id.currency_id.id
|
||||
result['currency_id'] = self.env.company_id.currency_id.id
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<record id="crm_lead_company_rule" model="ir.rule">
|
||||
<field name="name">CRM Lead Multi-Company</field>
|
||||
<field name="model_id" ref="model_crm_lead"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="crm_rule_all_lead" model="ir.rule">
|
||||
@@ -70,7 +70,7 @@
|
||||
<field name="name">CRM Lead Multi-Company</field>
|
||||
<field name="model_id" ref="model_crm_activity_report"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -43,7 +43,7 @@ class NewLeadNotification(TestCrmCases):
|
||||
self.assertTrue(lead_user.message_needaction)
|
||||
|
||||
def test_new_lead_from_email_multicompany(self):
|
||||
company0 = self.env.user.company_id
|
||||
company0 = self.env.company_id
|
||||
company1 = self.env['res.company'].create({'name': 'new_company'})
|
||||
|
||||
self.env.user.write({
|
||||
|
||||
@@ -273,7 +273,7 @@ class CRMRevealRule(models.Model):
|
||||
}
|
||||
|
||||
def _get_rules_payload(self):
|
||||
company_country = self.env.user.company_id.country_id
|
||||
company_country = self.env.company_id.country_id
|
||||
rule_payload = {}
|
||||
for rule in self:
|
||||
data = {
|
||||
|
||||
@@ -74,7 +74,7 @@ class StockPicking(models.Model):
|
||||
|
||||
carrier_price = fields.Float(string="Shipping Cost")
|
||||
delivery_type = fields.Selection(related='carrier_id.delivery_type', readonly=True)
|
||||
carrier_id = fields.Many2one("delivery.carrier", string="Carrier")
|
||||
carrier_id = fields.Many2one("delivery.carrier", string="Carrier", domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
||||
volume = fields.Float(copy=False)
|
||||
weight = fields.Float(compute='_cal_weight', digits=dp.get_precision('Stock Weight'), store=True, help="Total weight of the products in the picking.")
|
||||
carrier_tracking_ref = fields.Char(string='Tracking Reference', copy=False)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<field name="name">Delivery Carrier multi-company</field>
|
||||
<field name="model_id" ref="model_delivery_carrier"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field>
|
||||
<field name="domain_force"> ['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field>
|
||||
<field name="active" eval="False"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
@@ -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.user.company_id.id])
|
||||
[self.env.ref('base.USD').id, self.env.company_id.id])
|
||||
self.pricelist.currency_id = self.env.ref('base.USD').id
|
||||
|
||||
def test_00_delivery_cost(self):
|
||||
|
||||
@@ -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.user.company_id.id)
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id.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')
|
||||
|
||||
@@ -101,12 +101,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['res.company']._company_default_get('event.event'),
|
||||
default=lambda self: self.env.company_id,
|
||||
required=False, readonly=False, states={'done': [('readonly', True)]})
|
||||
organizer_id = fields.Many2one(
|
||||
'res.partner', string='Organizer',
|
||||
tracking=True,
|
||||
default=lambda self: self.env.user.company_id.partner_id)
|
||||
default=lambda self: self.env.company_id.partner_id)
|
||||
event_type_id = fields.Many2one(
|
||||
'event.type', string='Category',
|
||||
readonly=False, states={'done': [('readonly', True)]},
|
||||
@@ -165,7 +165,7 @@ class EventEvent(models.Model):
|
||||
is_online = fields.Boolean('Online Event')
|
||||
address_id = fields.Many2one(
|
||||
'res.partner', string='Location',
|
||||
default=lambda self: self.env.user.company_id.partner_id,
|
||||
default=lambda self: self.env.company_id.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)
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',
|
||||
('company_id', '=', False),
|
||||
('company_id', 'child_of', [user.company_id.id]),
|
||||
('company_id', 'in', company_ids),
|
||||
]
|
||||
</field>
|
||||
</record>
|
||||
@@ -42,7 +42,7 @@
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',
|
||||
('company_id', '=', False),
|
||||
('company_id', 'child_of', [user.company_id.id]),
|
||||
('company_id', 'in', company_ids),
|
||||
]
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = self.event_id.company_id or self.env.company_id
|
||||
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())
|
||||
|
||||
@@ -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['res.company']._company_default_get())
|
||||
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id)
|
||||
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)')
|
||||
|
||||
@@ -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['res.company']._company_default_get())
|
||||
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company_id)
|
||||
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
|
||||
|
||||
def _get_odometer(self):
|
||||
|
||||
@@ -66,7 +66,7 @@ class GoalDefinition(models.Model):
|
||||
items = []
|
||||
|
||||
if goal.monetary:
|
||||
items.append(self.env.user.company_id.currency_id.symbol or u'¤')
|
||||
items.append(self.env.company_id.currency_id.symbol or u'¤')
|
||||
if goal.suffix:
|
||||
items.append(goal.suffix)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<record id="goal_global_multicompany" model="ir.rule">
|
||||
<field name="name">Multicompany rule on challenges</field>
|
||||
<field name="model_id" ref="model_gamification_goal"/>
|
||||
<field name="domain_force">[('user_id.company_id', 'child_of', [user.company_id.id])]</field>
|
||||
<field name="domain_force">[('user_id.company_id', 'in', company_ids)]</field>
|
||||
<field name="global" eval="True"/>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id)
|
||||
state = fields.Selection([
|
||||
('recruit', 'Recruitment in Progress'),
|
||||
('open', 'Not Recruiting')
|
||||
@@ -379,7 +379,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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company_id)
|
||||
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)
|
||||
|
||||
@@ -16,8 +16,7 @@ class Partner(models.Model):
|
||||
|
||||
try:
|
||||
employee_group = self.env.ref('base.group_user')
|
||||
hr_suggestions = [{'id': user.partner_id.id, 'name': user.name, 'email': user.email}
|
||||
for user in employee_group.users]
|
||||
hr_suggestions = [{'id': user.partner_id.id, 'name': user.name, 'email': user.email} for user in employee_group.users]
|
||||
suggestions.append(hr_suggestions)
|
||||
return suggestions
|
||||
except AccessError:
|
||||
|
||||
@@ -30,21 +30,21 @@
|
||||
<field name="name">Employee multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_employee"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_dept_comp_rule" model="ir.rule">
|
||||
<field name="name">Department multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_department"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_job_comp_rule" model="ir.rule">
|
||||
<field name="name">Job multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_job"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -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.user.company_id
|
||||
company = self.env.company_id
|
||||
employees = self.env['hr.employee'].search([
|
||||
('department_id.company_id', '=', company.id),
|
||||
('user_id', '!=', False),
|
||||
|
||||
@@ -66,7 +66,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['res.company']._company_default_get().resource_calendar_id.id)
|
||||
default=lambda self: self.env.company_id.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')
|
||||
@@ -79,7 +79,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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id)
|
||||
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)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<field name="name">HR Contract: Multi Company</field>
|
||||
<field name="model_id" ref="model_hr_contract"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -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.user.company_id)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.user.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_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_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.user.company_id.id,
|
||||
'company_id': self.env.company_id.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.user.company_id)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user.company_id.currency_id)
|
||||
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)
|
||||
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.user.company_id.currency_id).rounding))
|
||||
.filtered(lambda r: not float_is_zero(r.total_amount, precision_rounding=(r.currency_id or self.env.company_id.currency_id).rounding))
|
||||
res = expense_line_ids.action_move_create()
|
||||
|
||||
if not self.accounting_date:
|
||||
|
||||
@@ -55,13 +55,13 @@
|
||||
<field name="name">Expense multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_expense"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
<record id="hr_expense_report_comp_rule" model="ir.rule">
|
||||
<field name="name">Expense Report multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_expense_sheet"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -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.user.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.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.user.company_id.id,
|
||||
'company_id': self.env.company_id.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.user.company_id.currency_id, "Currency 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.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):
|
||||
|
||||
@@ -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.user.company_id.currency_id)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self.env.company_id.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',
|
||||
|
||||
@@ -278,7 +278,7 @@ class HolidaysRequest(models.Model):
|
||||
self.date_to = False
|
||||
return
|
||||
|
||||
domain = [('calendar_id', '=', self.employee_id.resource_calendar_id.id or self.env.user.company_id.resource_calendar_id.id)]
|
||||
domain = [('calendar_id', '=', self.employee_id.resource_calendar_id.id or self.env.company_id.resource_calendar_id.id)]
|
||||
attendances = self.env['resource.calendar.attendance'].search(domain, order='dayofweek, day_period DESC')
|
||||
|
||||
# find first attendance coming after first_day
|
||||
@@ -341,7 +341,7 @@ class HolidaysRequest(models.Model):
|
||||
self.category_id = False
|
||||
elif self.holiday_type == 'company' and not self.mode_company_id:
|
||||
self.employee_id = False
|
||||
self.mode_company_id = self.env.user.company_id.id
|
||||
self.mode_company_id = self.env.company_id.id
|
||||
self.category_id = False
|
||||
elif self.holiday_type == 'department' and not self.department_id:
|
||||
self.employee_id = False
|
||||
@@ -376,7 +376,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.user.company_id.resource_calendar_id
|
||||
calendar = holiday.employee_id.resource_calendar_id or self.env.company_id.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)
|
||||
@@ -438,12 +438,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.user.company_id.resource_calendar_id.get_work_hours_count(
|
||||
today_hours = self.env.company_id.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.user.company_id.resource_calendar_id.get_work_hours_count(date_from, date_to) / (today_hours or HOURS_PER_DAY)
|
||||
return self.env.company_id.resource_calendar_id.get_work_hours_count(date_from, date_to) / (today_hours or HOURS_PER_DAY)
|
||||
|
||||
####################################################
|
||||
# ORM Overrides methods
|
||||
@@ -563,6 +563,9 @@ class HolidaysRequest(models.Model):
|
||||
def copy_data(self, default=None):
|
||||
raise UserError(_('A leave cannot be duplicated.'))
|
||||
|
||||
def _get_mail_redirect_suggested_company(self):
|
||||
return self.holiday_status_id.company_id
|
||||
|
||||
####################################################
|
||||
# Business methods
|
||||
####################################################
|
||||
@@ -606,7 +609,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.user.company_id.resource_calendar_id
|
||||
calendar = self.employee_id.resource_calendar_id or self.env.company_id.resource_calendar_id
|
||||
meeting_values = {
|
||||
'name': self.display_name,
|
||||
'categ_ids': [(6, 0, [
|
||||
|
||||
@@ -365,6 +365,9 @@ class HolidaysAllocation(models.Model):
|
||||
def copy_data(self, default=None):
|
||||
raise UserError(_('A time off cannot be duplicated.'))
|
||||
|
||||
def _get_mail_redirect_suggested_company(self):
|
||||
return self.holiday_status_id.company_id
|
||||
|
||||
####################################################
|
||||
# Business methods
|
||||
####################################################
|
||||
|
||||
@@ -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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company_id)
|
||||
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'",)
|
||||
@@ -208,7 +208,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.user.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.id)], limit=1).id
|
||||
return employee_id
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<field name="name">Time Off: multi company global rule</field>
|
||||
<field name="model_id" ref="model_hr_leave"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|', ('holiday_status_id.company_id', '=', False), ('holiday_status_id.company_id', 'in', [user.company_id.id])]</field>
|
||||
<field name="domain_force">['|', ('holiday_status_id.company_id', '=', False), ('holiday_status_id.company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_leave_allocation_rule_employee" model="ir.rule">
|
||||
@@ -145,7 +145,7 @@
|
||||
<field name="name">Time Off multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_leave_type"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','in',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -9,12 +9,17 @@ from odoo.http import request
|
||||
class HrOrgChartController(http.Controller):
|
||||
_managers_level = 5 # FP request
|
||||
|
||||
def _check_employee(self, employee_id):
|
||||
def _check_employee(self, employee_id, **kw):
|
||||
if not employee_id: # to check
|
||||
return None
|
||||
employee_id = int(employee_id)
|
||||
|
||||
Employee = request.env['hr.employee']
|
||||
if ('context' in kw and 'allowed_company_ids' in kw['context']):
|
||||
cids = kw['context']['allowed_company_ids']
|
||||
else:
|
||||
cids = [request.env.company_id.id]
|
||||
|
||||
Employee = request.env['hr.employee'].with_context(allowed_company_ids=cids)
|
||||
# check and raise
|
||||
if not Employee.check_access_rights('read', raise_exception=False):
|
||||
return None
|
||||
@@ -38,9 +43,9 @@ class HrOrgChartController(http.Controller):
|
||||
)
|
||||
|
||||
@http.route('/hr/get_org_chart', type='json', auth='user')
|
||||
def get_org_chart(self, employee_id):
|
||||
def get_org_chart(self, employee_id, **kw):
|
||||
|
||||
employee = self._check_employee(employee_id)
|
||||
employee = self._check_employee(employee_id, **kw)
|
||||
if not employee: # to check
|
||||
return {}
|
||||
|
||||
@@ -64,15 +69,14 @@ class HrOrgChartController(http.Controller):
|
||||
return values
|
||||
|
||||
@http.route('/hr/get_subordinates', type='json', auth='user')
|
||||
def get_subordinates(self, employee_id, subordinates_type=None):
|
||||
def get_subordinates(self, employee_id, subordinates_type=None, **kw):
|
||||
"""
|
||||
Get employee subordinates.
|
||||
Possible values for 'subordinates_type':
|
||||
- 'indirect'
|
||||
- 'direct'
|
||||
"""
|
||||
|
||||
employee = self._check_employee(employee_id)
|
||||
employee = self._check_employee(employee_id, **kw)
|
||||
if not employee: # to check
|
||||
return {}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ var AbstractField = require('web.AbstractField');
|
||||
var concurrency = require('web.concurrency');
|
||||
var core = require('web.core');
|
||||
var field_registry = require('web.field_registry');
|
||||
var session = require('web.session');
|
||||
|
||||
var QWeb = core.qweb;
|
||||
var _t = core._t;
|
||||
@@ -41,7 +42,8 @@ var FieldOrgChart = AbstractField.extend({
|
||||
return this.dm.add(this._rpc({
|
||||
route: '/hr/get_org_chart',
|
||||
params: {
|
||||
employee_id: employee_id
|
||||
employee_id: employee_id,
|
||||
context: session.user_context,
|
||||
},
|
||||
})).then(function (data) {
|
||||
self.orgData = data;
|
||||
@@ -59,7 +61,8 @@ var FieldOrgChart = AbstractField.extend({
|
||||
route: '/hr/get_subordinates',
|
||||
params: {
|
||||
employee_id: employee_id,
|
||||
subordinates_type: type
|
||||
subordinates_type: type,
|
||||
context: session.user_context,
|
||||
},
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -28,7 +28,7 @@ class ResCompany(models.Model):
|
||||
|
||||
@api.model
|
||||
def _check_presence(self):
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
if not company.hr_presence_last_compute_date or \
|
||||
company.hr_presence_last_compute_date.day != Datetime.now().day:
|
||||
self.env['hr.employee'].search([
|
||||
|
||||
@@ -10,7 +10,7 @@ class Job(models.Model):
|
||||
|
||||
@api.model
|
||||
def _default_address_id(self):
|
||||
return self.env.user.company_id.partner_id
|
||||
return self.env.company_id.partner_id
|
||||
|
||||
def _get_default_favorite_user_ids(self):
|
||||
return [(6, 0, [self.env.uid])]
|
||||
|
||||
@@ -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['res.company']._company_default_get('hr.applicant')
|
||||
company_id = self.env.company_id
|
||||
return company_id
|
||||
|
||||
name = fields.Char("Subject / Application Name", required=True)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<field name="name">Applicant multi company rule</field>
|
||||
<field name="model_id" ref="model_hr_applicant"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record id="group_hr_recruitment_user" model="res.groups">
|
||||
|
||||
@@ -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.user.company_id.timesheet_encode_uom_id
|
||||
encoding_uom = self.env.company_id.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.user.company_id, timesheet.date)
|
||||
amount, timesheet.account_id.currency_id, self.env.company_id, timesheet.date)
|
||||
result[timesheet.id].update({
|
||||
'amount': amount_converted,
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ class Http(models.AbstractModel):
|
||||
"""
|
||||
result = super(Http, self).session_info()
|
||||
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
encoding_uom = company.timesheet_encode_uom_id
|
||||
|
||||
result['timesheet_uom'] = encoding_uom.read(['name', 'rounding', 'timesheet_widget'])[0]
|
||||
|
||||
@@ -49,7 +49,7 @@ class Project(models.Model):
|
||||
if allow_timesheets and not values.get('analytic_account_id'):
|
||||
analytic_account = self.env['account.analytic.account'].create({
|
||||
'name': values.get('name', _('Unknown Analytic Account')),
|
||||
'company_id': values.get('company_id', self.env.user.company_id.id),
|
||||
'company_id': values.get('company_id', self.env.company_id.id),
|
||||
'partner_id': values.get('partner_id'),
|
||||
'active': True,
|
||||
})
|
||||
|
||||
@@ -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.user.company_id)
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id)
|
||||
|
||||
@api.model
|
||||
def get(self, service_name, force_create=True):
|
||||
account = self.search([('service_name', '=', service_name), ('company_id', 'in', [self.env.user.company_id.id, False])])
|
||||
account = self.search([('service_name', '=', service_name), ('company_id', 'in', [self.env.company_id.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,
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
<field name="model_id" ref="model_iap_account"/>
|
||||
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
|
||||
<!-- partners can CUD services linked to themselves -->
|
||||
<field name="domain_force">[
|
||||
('company_id', 'in', [user.company_id.id, False]),
|
||||
]</field>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -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.user.company_id
|
||||
company = self.env.company_id
|
||||
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})
|
||||
|
||||
@@ -9,7 +9,7 @@ class AccountChartTemplate(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_default_bank_journals_data(self):
|
||||
if self.env.user.company_id.country_id and self.env.user.company_id.country_id.code.upper() == 'DO':
|
||||
if self.env.company_id.country_id and self.env.company_id.country_id.code.upper() == 'DO':
|
||||
return [
|
||||
{'acc_name': _('Cash'), 'account_type': 'cash'},
|
||||
{'acc_name': _('Caja Chica'), 'account_type': 'cash'},
|
||||
|
||||
@@ -18,7 +18,7 @@ class l10n_eu_service(models.TransientModel):
|
||||
return eu_group
|
||||
|
||||
def _get_default_company_id(self):
|
||||
return self.env.user.company_id.id
|
||||
return self.env.company_id.id
|
||||
|
||||
def _default_fiscal_position_id(self):
|
||||
user = self.env.user
|
||||
|
||||
@@ -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.user.company_id.id)
|
||||
action = env['account.move']._check_hash_integrity(env.company_id.id)
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -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.user.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_id.name)
|
||||
previous_hash = u''
|
||||
start_move_info = []
|
||||
for move in moves:
|
||||
|
||||
@@ -65,7 +65,7 @@ class AccountFrFec(models.TransientModel):
|
||||
sql_query += '''
|
||||
AND am.state = 'posted'
|
||||
'''
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company_id
|
||||
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.user.company_id
|
||||
company = self.env.company_id
|
||||
company_legal_data = self._get_company_legal_data(company)
|
||||
|
||||
header = [
|
||||
|
||||
@@ -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.user.company_id.id)
|
||||
action = env['pos.order']._check_hash_integrity(env.company_id.id)
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -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.user.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_id.name)
|
||||
previous_hash = u''
|
||||
start_order_info = []
|
||||
for order in orders:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<record model="ir.rule" id="account_sale_closing_multi_company">
|
||||
<field name="name">Sale Closing multi-company</field>
|
||||
<field name="model_id" ref="model_account_sale_closing"/>
|
||||
<field name="domain_force">[('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.journal').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
|
||||
@@ -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['res.company']._company_default_get('account.account').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.account').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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['res.company']._company_default_get('account.account').id)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.bank.statement.line" name="fast_counterpart_creation">
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 14),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -37,7 +37,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -50,7 +50,7 @@
|
||||
<field name="invoice_line_tax_ids" model="account.tax"
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id),
|
||||
('company_id', '=', obj().env.company_id.id),
|
||||
'|',
|
||||
('children_tax_ids.amount', '=', 9),
|
||||
'&',
|
||||
@@ -89,7 +89,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -103,7 +103,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -117,7 +117,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 2.5),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -131,7 +131,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 2.5),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.invoice" name="_onchange_invoice_line_ids">
|
||||
@@ -164,7 +164,7 @@
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('tax_group_id', '=', obj().env.ref('l10n_in.igst_group').id),
|
||||
('amount','=', 18),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.invoice" name="_onchange_invoice_line_ids">
|
||||
@@ -187,7 +187,7 @@
|
||||
eval="obj().search([
|
||||
('type', '=', 'sale'),
|
||||
('l10n_in_import_export', '=', True),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.journal').id)], limit=1).id
|
||||
('company_id', '=', obj().env.company_id.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'"/>
|
||||
@@ -207,7 +207,7 @@
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('tax_group_id', '=', obj().env.ref('l10n_in.igst_group').id),
|
||||
('amount','=', 18),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.invoice" name="_onchange_invoice_line_ids">
|
||||
@@ -239,7 +239,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['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -253,7 +253,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['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 14),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -303,7 +303,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.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"/>
|
||||
@@ -316,7 +316,7 @@
|
||||
<field name="invoice_line_tax_ids" model="account.tax"
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id),
|
||||
('company_id', '=', obj().env.company_id.id),
|
||||
'|',
|
||||
('children_tax_ids.amount', '=', 9),
|
||||
'&',
|
||||
@@ -356,7 +356,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.invoice" name="_onchange_invoice_line_ids">
|
||||
@@ -389,7 +389,7 @@
|
||||
eval="[(6, 0, obj().search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('children_tax_ids.amount','=', 9),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.tax').id)], limit=1).ids)]"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).ids)]"/>
|
||||
</record>
|
||||
|
||||
<function model="account.invoice" name="_onchange_invoice_line_ids">
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
<field name="journal_id" model="account.journal"
|
||||
eval="obj().search([
|
||||
('type', '=', 'cash'),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.journal').id)], limit=1).id"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).id"/>
|
||||
<field name="payment_method_id" model="account.journal"
|
||||
eval="obj().search([
|
||||
('type', '=', 'cash'),
|
||||
('company_id', '=', obj().env['res.company']._company_default_get('account.journal').id)], limit=1).inbound_payment_method_ids[0].id"/>
|
||||
('company_id', '=', obj().env.company_id.id)], limit=1).inbound_payment_method_ids[0].id"/>
|
||||
</record>
|
||||
|
||||
<function model="account.payment" name="post">
|
||||
|
||||
@@ -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.user.company_id.l10n_it_address_recipient_fatturapa),
|
||||
'body': _('Sending file: %s to ES: %s') % (self.l10n_it_einvoice_id.name, self.env.company_id.l10n_it_address_recipient_fatturapa),
|
||||
'author_id': self.env.user.partner_id.id,
|
||||
'email_from': self.env.user.company_id.l10n_it_address_send_fatturapa,
|
||||
'mail_server_id': self.env.user.company_id.l10n_it_mail_pec_server_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,
|
||||
'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.user.company_id.l10n_it_address_recipient_fatturapa,
|
||||
'email_to': self.env.company_id.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.user.company_id
|
||||
company = self.env.company_id
|
||||
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.user.company_id != company:
|
||||
raise UserError(_("You can only import invoice concern your current company: %s") % self.env.user.company_id.display_name)
|
||||
if self.env.company_id != company:
|
||||
raise UserError(_("You can only import invoice concern your current company: %s") % self.env.company_id.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.user.company_id.currency_id and currency.active:
|
||||
if currency != self.env.company_id.currency_id and currency.active:
|
||||
invoice_form.currency_id = currency
|
||||
|
||||
# Date. <2.1.1.3>
|
||||
|
||||
@@ -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.user.company_id.country_id.code == 'NL':
|
||||
account = self.env['account.account'].search([('code', '=', '999999'), ('company_id', '=', self.env.user.company_id.id)])
|
||||
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 account:
|
||||
account.tag_ids = [(4, self.env.ref('l10n_nl.account_tag_12').id)]
|
||||
return res
|
||||
|
||||
@@ -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['res.company']._company_default_get())
|
||||
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company_id)
|
||||
user_id = fields.Many2one('res.users', 'User',
|
||||
default=lambda self: self.env.uid)
|
||||
date = fields.Date('Date', required=True, default=fields.Date.context_today)
|
||||
|
||||
@@ -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', related='user_id.company_id', store=True)
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id.id)
|
||||
currency_id = fields.Many2one('res.currency', related='company_id.currency_id', readonly=True, store=True)
|
||||
quantity = fields.Float('Quantity', required=True, default=1)
|
||||
|
||||
|
||||
@@ -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['res.company']._company_default_get())
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id)
|
||||
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
|
||||
topping_label_1 = fields.Char('Topping Label 1', required=True, default='Supplements')
|
||||
topping_label_2 = fields.Char('Topping Label 2', required=True, default='Beverages')
|
||||
@@ -60,14 +60,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['res.company']._company_default_get())
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id)
|
||||
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.user.company_id.currency_id
|
||||
currency_id = self.env.company_id.currency_id
|
||||
res = dict(super(LunchTopping, self).name_get())
|
||||
for topping in self:
|
||||
price = formatLang(self.env, topping.price, currency_obj=currency_id)
|
||||
@@ -88,7 +88,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['res.company']._company_default_get())
|
||||
company_id = fields.Many2one('res.company', default=lambda self: self.env.company_id)
|
||||
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
|
||||
|
||||
# image: all image fields are base64 encoded and PIL-supported
|
||||
|
||||
@@ -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.user.company_id.currency_id)
|
||||
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company_id.currency_id)
|
||||
|
||||
product_id = fields.Many2one('lunch.product', string='Product ID')
|
||||
product_description = fields.Text('Description', related='product_id.description')
|
||||
|
||||
@@ -52,6 +52,7 @@ class MailController(http.Controller):
|
||||
# access_token and kwargs are used in the portal controller override for the Send by email or Share Link
|
||||
# to give access to the record to a recipient that has normally no access.
|
||||
uid = request.session.uid
|
||||
user = request.env['res.users'].sudo().browse(uid)
|
||||
|
||||
# no model / res_id, meaning no possible record -> redirect to login
|
||||
if not model or not res_id or model not in request.env:
|
||||
@@ -69,7 +70,33 @@ class MailController(http.Controller):
|
||||
if not RecordModel.sudo(uid).check_access_rights('read', raise_exception=False):
|
||||
return cls._redirect_to_messaging()
|
||||
try:
|
||||
record_sudo.sudo(uid).check_access_rule('read')
|
||||
# We need here to extend the "allowed_company_ids" to allow a redirection
|
||||
# to any record that the user can access, regardless of currently visible
|
||||
# records based on the "currently allowed companies".
|
||||
cids = request.httprequest.cookies.get('cids', str(request.env.user.company_id))
|
||||
cids = [int(cid) for cid in cids.split(',')]
|
||||
try:
|
||||
record_sudo.sudo(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
except AccessError:
|
||||
# In case the allowed_company_ids from the cookies (i.e. the last user configuration
|
||||
# on his browser) is not sufficient to avoid an ir.rule access error, try to following
|
||||
# heuristic:
|
||||
# - Guess the supposed necessary company to access the record via the method
|
||||
# _get_mail_redirect_suggested_company
|
||||
# - If no company, then redirect to the messaging
|
||||
# - If the multi company per tag group is activated, merge the suggested company
|
||||
# withe the companies on the cookie
|
||||
# - else, use this company as enabled company
|
||||
# - Make a new access test if it succeeds, redirect to the record. Otherwise,
|
||||
# redirect to the messaging.
|
||||
suggested_company = record_sudo._get_mail_redirect_suggested_company()
|
||||
if not suggested_company:
|
||||
raise AccessError()
|
||||
if user.has_group('base.group_toggle_company'):
|
||||
cids += [suggested_company]
|
||||
else:
|
||||
cids = [suggested_company]
|
||||
record_sudo.sudo(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
except AccessError:
|
||||
return cls._redirect_to_messaging()
|
||||
else:
|
||||
@@ -98,6 +125,7 @@ class MailController(http.Controller):
|
||||
if view_id:
|
||||
url_params['view_id'] = view_id
|
||||
|
||||
url_params['cids'] = ','.join([str(cid) for cid in cids])
|
||||
url = '/web?#%s' % url_encode(url_params)
|
||||
return werkzeug.utils.redirect(url)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user