diff options
| -rw-r--r-- | addons/account/models/account.py | 101 | ||||
| -rw-r--r-- | addons/account/models/account_analytic_line.py | 6 | ||||
| -rw-r--r-- | addons/account/models/account_bank_statement.py | 8 | ||||
| -rw-r--r-- | addons/account/models/account_cash_rounding.py | 4 | ||||
| -rw-r--r-- | addons/account/models/account_move.py | 44 | ||||
| -rw-r--r-- | addons/account/models/account_payment.py | 8 | ||||
| -rw-r--r-- | addons/account/models/account_reconcile_model.py | 26 | ||||
| -rw-r--r-- | addons/account/models/partner.py | 27 | ||||
| -rw-r--r-- | addons/account/views/account_move_views.xml | 2 | ||||
| -rw-r--r-- | addons/account/views/account_view.xml | 15 | ||||
| -rw-r--r-- | addons/account/wizard/account_accrual_accounting.py | 2 | ||||
| -rw-r--r-- | addons/account/wizard/account_move_reversal.py | 6 | ||||
| -rw-r--r-- | addons/account/wizard/account_move_reversal_view.xml | 1 | ||||
| -rw-r--r-- | addons/account/wizard/setup_wizards.py | 6 | ||||
| -rw-r--r-- | addons/account/wizard/setup_wizards_view.xml | 4 | ||||
| -rw-r--r-- | addons/analytic/models/analytic_account.py | 12 | ||||
| -rw-r--r-- | addons/point_of_sale/tests/common.py | 4 |
17 files changed, 191 insertions, 85 deletions
diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 81fee22bd30..e999cae4bc3 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -340,6 +340,7 @@ class AccountAccount(models.Model): _name = "account.account" _description = "Account" _order = "code, company_id" + _check_company_auto = True @api.constrains('internal_type', 'reconcile') def _check_reconcile(self): @@ -372,9 +373,11 @@ class AccountAccount(models.Model): reconcile = fields.Boolean(string='Allow Reconciliation', default=False, help="Check this box if this account allows invoices & payments matching of journal items.") tax_ids = fields.Many2many('account.tax', 'account_account_tax_default_rel', - 'account_id', 'tax_id', string='Default Taxes', context={'append_type_to_tax_name': True}) + 'account_id', 'tax_id', string='Default Taxes', + check_company=True, + context={'append_type_to_tax_name': True}) note = fields.Text('Internal Notes') - company_id = fields.Many2one('res.company', string='Company', required=True, + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting") group_id = fields.Many2one('account.group', compute='_compute_account_group', store=True) @@ -731,7 +734,7 @@ class AccountGroup(models.Model): name = fields.Char(required=True) code_prefix_start = fields.Char() code_prefix_end = fields.Char() - company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company) + company_id = fields.Many2one('res.company', required=True, readonly=True, default=lambda self: self.env.company) _sql_constraints = [ ( @@ -901,10 +904,12 @@ class AccountRoot(models.Model): class AccountJournalGroup(models.Model): _name = 'account.journal.group' _description = "Account Journal Group" + _check_company_auto = True name = fields.Char("Journal Group", required=True, translate=True) company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company) - excluded_journal_ids = fields.Many2many('account.journal', string="Excluded Journals", domain="[('company_id', '=', company_id)]") + excluded_journal_ids = fields.Many2many('account.journal', string="Excluded Journals", domain="[('company_id', '=', company_id)]", + check_company=True) sequence = fields.Integer(default=10) @@ -913,6 +918,7 @@ class AccountJournal(models.Model): _description = "Journal" _order = 'sequence, type, code' _inherit = ['mail.thread', 'mail.activity.mixin'] + _check_company_auto = True def _default_inbound_payment_methods(self): return self.env.ref('account.account_payment_method_manual_in') @@ -942,11 +948,15 @@ class AccountJournal(models.Model): "Select 'General' for miscellaneous operations journals.") type_control_ids = fields.Many2many('account.account.type', 'journal_account_type_control_rel', 'journal_id', 'type_id', string='Account Types Allowed') account_control_ids = fields.Many2many('account.account', 'journal_account_control_rel', 'journal_id', 'account_id', string='Accounts Allowed', + check_company=True, domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") default_credit_account_id = fields.Many2one('account.account', string='Default Credit Account', - domain=[('deprecated', '=', False)], help="It acts as a default account for credit amount", + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + help="It acts as a default account for credit amount", + check_company=True, ondelete='restrict') default_debit_account_id = fields.Many2one('account.account', string='Default Debit Account', + check_company=True, domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", help="It acts as a default account for debit amount", ondelete='restrict') restrict_mode_hash_table = fields.Boolean(string="Lock Posted Entries with Hash", help="If ticked, the accounting entry or invoice receives a hash as soon as it is posted and cannot be modified anymore.") @@ -957,7 +967,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") - company_id = fields.Many2one('res.company', string='Company', required=True, index=True, default=lambda self: self.env.company, + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, index=True, default=lambda self: self.env.company, help="Company related to this journal") refund_sequence = fields.Boolean(string='Dedicated Credit Note Sequence', help="Check this box if you don't want to share the same sequence for invoices and credit notes made from this journal", default=False) @@ -979,12 +989,24 @@ class AccountJournal(models.Model): "SEPA Credit Transfer: Pay bill from a SEPA Credit Transfer file you submit to your bank. Enable this option from the settings.") at_least_one_inbound = fields.Boolean(compute='_methods_compute', store=True) at_least_one_outbound = fields.Boolean(compute='_methods_compute', store=True) - profit_account_id = fields.Many2one('account.account', domain="[('company_id', '=', company_id)]", string='Profit Account', help="Used to register a profit when the ending balance of a cash register differs from what the system computes") - loss_account_id = fields.Many2one('account.account', domain="[('company_id', '=', company_id)]", string='Loss Account', help="Used to register a loss when the ending balance of a cash register differs from what the system computes") + profit_account_id = fields.Many2one('account.account', + string='Profit Account', + domain="[('company_id', '=', company_id)]", + check_company=True, + help="Used to register a profit when the ending balance of a cash register differs from what the system computes") + loss_account_id = fields.Many2one('account.account', + string='Loss Account', + domain="[('company_id', '=', company_id)]", + check_company=True, + help="Used to register a loss when the ending balance of a cash register differs from what the system computes") # Bank journals fields company_partner_id = fields.Many2one('res.partner', related='company_id.partner_id', string='Account Holder', readonly=True, store=False) - bank_account_id = fields.Many2one('res.partner.bank', string="Bank Account", ondelete='restrict', copy=False, domain="[('partner_id','=', company_partner_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]") + bank_account_id = fields.Many2one('res.partner.bank', + string="Bank Account", + ondelete='restrict', copy=False, + check_company=True, + domain="[('partner_id','=', company_partner_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]") bank_statements_source = fields.Selection(selection=_get_bank_statements_available_sources, string='Bank Feeds', default='undefined', help="Defines how the bank statements will be registered") bank_acc_number = fields.Char(related='bank_account_id.acc_number', readonly=False) bank_id = fields.Many2one('res.bank', related='bank_account_id.bank_id', readonly=False) @@ -1000,9 +1022,15 @@ class AccountJournal(models.Model): alias_domain = fields.Char('Alias domain', compute='_compute_alias_domain', default=lambda self: self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain")) alias_name = fields.Char('Alias Name', related='alias_id.alias_name', help="It creates draft invoices and bills by sending an email.", readonly=False) - journal_group_ids = fields.Many2many('account.journal.group', domain="[('company_id', '=', company_id)]", string="Journal Groups") + journal_group_ids = fields.Many2many('account.journal.group', + domain="[('company_id', '=', company_id)]", + check_company=True, + string="Journal Groups") - secure_sequence_id = fields.Many2one('ir.sequence', help='Sequence to use to ensure the securisation of data', readonly=True, copy=False) + secure_sequence_id = fields.Many2one('ir.sequence', + help='Sequence to use to ensure the securisation of data', + check_company=True, + readonly=True, copy=False) _sql_constraints = [ ('code_company_uniq', 'unique (code, name, company_id)', 'The code and name of the journal must be unique per company !'), @@ -1056,7 +1084,7 @@ class AccountJournal(models.Model): def _check_bank_account(self): for journal in self: if journal.type == 'bank' and journal.bank_account_id: - if journal.bank_account_id.company_id != journal.company_id: + if journal.bank_account_id.company_id and journal.bank_account_id.company_id != journal.company_id: raise ValidationError(_('The bank account of a bank journal must belong to the same company (%s).') % journal.company_id.name) # A bank account can belong to a customer/supplier, in which case their partner_id is the customer/supplier. # Or they are part of a bank journal and their partner_id must be the company's partner_id. @@ -1407,6 +1435,7 @@ class AccountTax(models.Model): _name = 'account.tax' _description = 'Tax' _order = 'sequence,id' + _check_company_auto = True @api.model def _default_tax_group(self): @@ -1428,8 +1457,11 @@ class AccountTax(models.Model): e.g 200 * (1 - 10%) = 180 (price included) """) active = fields.Boolean(default=True, help="Set active to false to hide the tax without removing it.") - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) - children_tax_ids = fields.Many2many('account.tax', 'account_tax_filiation_rel', 'parent_tax', 'child_tax', string='Children Taxes') + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) + children_tax_ids = fields.Many2many('account.tax', + 'account_tax_filiation_rel', 'parent_tax', 'child_tax', + check_company=True, + 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.") amount = fields.Float(required=True, digits=(16, 4)) @@ -1448,10 +1480,15 @@ class AccountTax(models.Model): ], string='Tax Due', default='on_invoice', help="Based on Invoice: the tax is due as soon as the invoice is validated.\n" "Based on Payment: the tax is due as soon as the payment of the invoice is received.") - cash_basis_transition_account_id = fields.Many2one(string="Cash Basis Transition Account", domain=[('deprecated', '=', False)], comodel_name='account.account', help="Account used to transition the tax amount for cash basis taxes. It will contain the tax amount as long as the original invoice has not been reconciled ; at reconciliation, this amount cancelled on this account and put on the regular tax account.") + cash_basis_transition_account_id = fields.Many2one(string="Cash Basis Transition Account", + check_company=True, + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + comodel_name='account.account', + help="Account used to transition the tax amount for cash basis taxes. It will contain the tax amount as long as the original invoice has not been reconciled ; at reconciliation, this amount cancelled on this account and put on the regular tax account.") cash_basis_base_account_id = fields.Many2one( 'account.account', - domain=[('deprecated', '=', False)], + check_company=True, + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", string='Base Tax Received Account', help='Account that will be set on lines created in cash basis journal entry and used to keep track of the tax base amount.') invoice_repartition_line_ids = fields.One2many(string="Repartition for Invoices", comodel_name="account.tax.repartition.line", inverse_name="invoice_tax_id", copy=True, help="Repartition when the tax is used on an invoice") @@ -1473,15 +1510,15 @@ class AccountTax(models.Model): if 'refund_repartition_line_ids' in vals: # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['refund_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), ] if 'invoice_repartition_line_ids' in vals: # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['invoice_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), ] return rslt @@ -1946,17 +1983,26 @@ class AccountTaxRepartitionLine(models.Model): _name = "account.tax.repartition.line" _description = "Tax Repartition Line" _order = 'sequence, repartition_type, id' + _check_company_auto = True factor_percent = fields.Float(string="%", required=True, help="Factor to apply on the account move lines generated from this repartition line, in percents") factor = fields.Float(string="Factor Ratio", compute="_compute_factor", help="Factor to apply on the account move lines generated from this repartition line") repartition_type = fields.Selection(string="Based On", selection=[('base', 'Base'), ('tax', 'of tax')], required=True, default='tax', help="Base on which the factor will be applied.") - account_id = fields.Many2one(string="Account", comodel_name='account.account', help="Account on which to post the tax amount") + account_id = fields.Many2one(string="Account", + comodel_name='account.account', + domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('internal_type', 'not in', ('receivable', 'payable'))]", + check_company=True, + help="Account on which to post the tax amount") tag_ids = fields.Many2many(string="Tax Grids", comodel_name='account.account.tag', domain=[('applicability', '=', 'taxes')], copy=True) - invoice_tax_id = fields.Many2one(comodel_name='account.tax', help="The tax set to apply this repartition on invoices. Mutually exclusive with refund_tax_id") - refund_tax_id = fields.Many2one(comodel_name='account.tax', help="The tax set to apply this repartition on refund invoices. Mutually exclusive with invoice_tax_id") + invoice_tax_id = fields.Many2one(comodel_name='account.tax', + check_company=True, + help="The tax set to apply this repartition on invoices. Mutually exclusive with refund_tax_id") + refund_tax_id = fields.Many2one(comodel_name='account.tax', + check_company=True, + help="The tax set to apply this repartition on refund invoices. Mutually exclusive with invoice_tax_id") tax_id = fields.Many2one(comodel_name='account.tax', compute='_compute_tax_id') - country_id = fields.Many2one(string="Country", comodel_name='res.country', related='company_id.country_id', help="Technical field used to restrict tags domain in form view.") - company_id = fields.Many2one(string="Company", comodel_name='res.company', required=True, default=lambda x: x.env.company, help="The company this repartition line belongs to.") + country_id = fields.Many2one(string="Country", comodel_name='res.country', related='company_id.country_id', help="Technical field used to restrict tags domain in form view.") + company_id = fields.Many2one(string="Company", comodel_name='res.company', compute="_compute_company", store=True, help="The company this repartition line belongs to.") sequence = fields.Integer(string="Sequence", default=1, help="The order in which display and match repartition lines. For refunds to work properly, invoice repartition lines should be arranged in the same order as the credit note repartition lines they correspond to.") @api.constrains('invoice_tax_id', 'refund_tax_id') @@ -1970,6 +2016,11 @@ class AccountTaxRepartitionLine(models.Model): for record in self: record.factor = record.factor_percent / 100.0 + @api.depends('invoice_tax_id.company_id', 'refund_tax_id.company_id') + def _compute_company(self): + for record in self: + record.company_id = record.invoice_tax_id and record.invoice_tax_id.company_id.id or record.refund_tax_id.company_id.id + @api.depends('invoice_tax_id', 'refund_tax_id') def _compute_tax_id(self): for record in self: diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index e5b45e92b1f..35737d8ab75 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -55,11 +55,11 @@ class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' _description = 'Analytic Line' - product_id = fields.Many2one('product.product', string='Product', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + product_id = fields.Many2one('product.product', string='Product', check_company=True) general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', readonly=True, - related='move_id.account_id', store=True, domain=[('deprecated', '=', False)], + related='move_id.account_id', store=True, domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", compute_sudo=True) - move_id = fields.Many2one('account.move.line', string='Journal Item', ondelete='cascade', index=True) + move_id = fields.Many2one('account.move.line', string='Journal Item', ondelete='cascade', index=True, check_company=True) code = fields.Char(size=8) ref = fields.Char(string='Ref.') diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 251f438577c..d3907af0e3d 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -228,6 +228,7 @@ class AccountBankStatement(models.Model): _description = "Bank Statement" _order = "date desc, name desc, id desc" _inherit = ['mail.thread', 'sequence.mixin'] + _check_company_auto = True name = fields.Char(string='Reference', states={'open': [('readonly', False)]}, copy=False, readonly=True) reference = fields.Char(string='External Reference', states={'open': [('readonly', False)]}, copy=False, readonly=True, help="Used to hold the reference of the external mean that created this statement (name of imported file, reference of online synchronization...)") @@ -239,7 +240,7 @@ class AccountBankStatement(models.Model): "This is useful if the accounting period in which the entries should normally be booked is already closed.") state = fields.Selection([('open', 'New'), ('confirm', 'Validated')], string='Status', required=True, readonly=True, copy=False, default='open') currency_id = fields.Many2one('res.currency', compute='_compute_currency', string="Currency") - journal_id = fields.Many2one('account.journal', string='Journal', required=True, states={'confirm': [('readonly', True)]}, default=_default_journal) + journal_id = fields.Many2one('account.journal', string='Journal', required=True, states={'confirm': [('readonly', True)]}, default=_default_journal, check_company=True) journal_type = fields.Selection(related='journal_id.type', help="Technical field used for usability purposes") company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', store=True, readonly=True, default=lambda self: self.env.company) @@ -469,10 +470,11 @@ class AccountBankStatementLine(models.Model): partner_id = fields.Many2one('res.partner', string='Partner') account_number = fields.Char(string='Bank Account Number', help="Technical field used to store the bank account number before its creation, upon the line's processing") bank_account_id = fields.Many2one('res.partner.bank', string='Bank Account', help="Bank account that was used in this transaction.") - account_id = fields.Many2one('account.account', string='Counterpart Account', domain=[('deprecated', '=', False)], + account_id = fields.Many2one('account.account', string='Counterpart Account', domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + check_company=True, help="This technical field can be used at the statement line creation/import time in order to avoid the reconciliation" " process on it later on. The statement line will simply create a counterpart on this account") - statement_id = fields.Many2one('account.bank.statement', string='Statement', index=True, required=True, ondelete='cascade') + statement_id = fields.Many2one('account.bank.statement', string='Statement', index=True, required=True, ondelete='cascade', check_company=True) journal_id = fields.Many2one('account.journal', related='statement_id.journal_id', string='Journal', store=True, readonly=True) partner_name = fields.Char(help="This field is used to record the third party name when importing bank statement in electronic format," " when the partner doesn't exist yet in the database (or cannot be found).") diff --git a/addons/account/models/account_cash_rounding.py b/addons/account/models/account_cash_rounding.py index d290c123f3c..7d105c60288 100644 --- a/addons/account/models/account_cash_rounding.py +++ b/addons/account/models/account_cash_rounding.py @@ -20,8 +20,8 @@ class AccountCashRounding(models.Model): strategy = fields.Selection([('biggest_tax', 'Modify tax amount'), ('add_invoice_line', 'Add a rounding line')], string='Rounding Strategy', default='add_invoice_line', required=True, help='Specify which way will be used to round the invoice amount to the rounding precision') - profit_account_id = fields.Many2one('account.account', string='Profit Account') - loss_account_id = fields.Many2one('account.account', string='Loss Account') + profit_account_id = fields.Many2one('account.account', string='Profit Account', company_dependent=True, domain="[('deprecated', '=', False), ('company_id', '=', current_company_id)]") + loss_account_id = fields.Many2one('account.account', string='Loss Account', company_dependent=True, domain="[('deprecated', '=', False), ('company_id', '=', current_company_id)]") rounding_method = fields.Selection(string='Rounding Method', required=True, selection=[('UP', 'UP'), ('DOWN', 'DOWN'), ('HALF-UP', 'HALF-UP')], default='HALF-UP', help='The tie-breaking rule used for float rounding operations') diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 5634952cf58..9f3c2abacef 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -35,6 +35,7 @@ class AccountMove(models.Model): _description = "Journal Entries" _order = 'date desc, name desc, id desc' _mail_post_access = 'read' + _check_company_auto = True @property def _sequence_monthly_regex(self): @@ -133,10 +134,11 @@ class AccountMove(models.Model): help='If this checkbox is ticked, it means that the user was not sure of all the related informations at the time of the creation of the move and that the move needs to be checked again.') journal_id = fields.Many2one('account.journal', string='Journal', required=True, readonly=True, states={'draft': [('readonly', False)]}, - domain="[('company_id', '=', company_id)]", + check_company=True, domain="[('id', 'in', suitable_journal_ids)]", default=_get_default_journal) + suitable_journal_ids = fields.Many2many('account.journal', compute='_compute_suitable_journal_ids') company_id = fields.Many2one(string='Company', store=True, readonly=True, - related='journal_id.company_id', change_default=True) + related='journal_id.company_id', change_default=True, default=lambda self: self.env.company) company_currency_id = fields.Many2one(string='Company Currency', readonly=True, related='journal_id.company_id.currency_id') currency_id = fields.Many2one('res.currency', store=True, readonly=True, tracking=True, required=True, @@ -147,7 +149,7 @@ class AccountMove(models.Model): states={'draft': [('readonly', False)]}) partner_id = fields.Many2one('res.partner', readonly=True, tracking=True, states={'draft': [('readonly', False)]}, - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", + check_company=True, string='Partner', change_default=True) commercial_partner_id = fields.Many2one('res.partner', string='Commercial Entity', store=True, readonly=True, compute='_compute_commercial_partner_id') @@ -196,7 +198,8 @@ class AccountMove(models.Model): help='If this checkbox is ticked, this entry will be automatically posted at its date.') # ==== Reverse feature fields ==== - reversed_entry_id = fields.Many2one('account.move', string="Reverse entry", readonly=True, copy=False) + reversed_entry_id = fields.Many2one('account.move', string="Reverse entry", readonly=True, copy=False, + check_company=True) # ========================================================= # Invoice related fields @@ -205,6 +208,7 @@ class AccountMove(models.Model): # ==== Business fields ==== fiscal_position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position', readonly=True, states={'draft': [('readonly', False)]}, + check_company=True, domain="[('company_id', '=', company_id)]", help="Fiscal positions are used to adapt taxes and accounts for particular customers or sales orders/invoices. " "The default value comes from the customer.") @@ -225,7 +229,7 @@ class AccountMove(models.Model): invoice_origin = fields.Char(string='Origin', readonly=True, tracking=True, help="The document(s) that generated the invoice.") invoice_payment_term_id = fields.Many2one('account.payment.term', string='Payment Terms', - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", + check_company=True, readonly=True, states={'draft': [('readonly', False)]}) # /!\ invoice_line_ids is just a subset of line_ids. invoice_line_ids = fields.One2many('account.move.line', 'move_id', string='Invoice lines', @@ -234,7 +238,7 @@ class AccountMove(models.Model): states={'draft': [('readonly', False)]}) invoice_partner_bank_id = fields.Many2one('res.partner.bank', string='Bank Account', help='Bank Account Number to which the invoice will be paid. A Company bank account if this is a Customer Invoice or Vendor Credit Note, otherwise a Partner bank account number.', - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + check_company=True) invoice_incoterm_id = fields.Many2one('account.incoterms', string='Incoterm', default=_get_default_invoice_incoterm, help='International Commercial Terms are a series of predefined commercial terms used in international transactions.') @@ -249,7 +253,7 @@ class AccountMove(models.Model): # ==== Vendor bill fields ==== invoice_vendor_bill_id = fields.Many2one('account.move', store=False, - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", + check_company=True, string='Vendor Bill', help="Auto-complete from a past bill.") invoice_source_email = fields.Char(string='Source Email', tracking=True) @@ -923,6 +927,12 @@ class AccountMove(models.Model): # COMPUTE METHODS # ------------------------------------------------------------------------- + @api.depends('company_id', 'invoice_filter_type_domain') + def _compute_suitable_journal_ids(self): + for m in self: + domain = [('company_id', '=', m.company_id.id), ('type', '=?', m.invoice_filter_type_domain)] + m.suitable_journal_ids = self.env['account.journal'].search(domain) + @api.depends('posted_before', 'state', 'highest_name') def _compute_name(self): for record in self.sorted(lambda m: (m.date, m.ref or '', m.id)): @@ -2448,24 +2458,27 @@ class AccountMoveLine(models.Model): _name = "account.move.line" _description = "Journal Item" _order = "date desc, move_name desc, id" + _check_company_auto = True # ==== Business fields ==== move_id = fields.Many2one('account.move', string='Journal Entry', index=True, required=True, readonly=True, auto_join=True, ondelete="cascade", + check_company=True, help="The move of this entry line.") move_name = fields.Char(string='Number', related='move_id.name', store=True, index=True) date = fields.Date(related='move_id.date', store=True, readonly=True, index=True, copy=False, group_operator='min') ref = fields.Char(related='move_id.ref', store=True, copy=False, index=True, readonly=False) parent_state = fields.Selection(related='move_id.state', store=True, readonly=True) journal_id = fields.Many2one(related='move_id.journal_id', store=True, index=True, copy=False) - company_id = fields.Many2one(related='move_id.company_id', store=True, readonly=True) + company_id = fields.Many2one(related='move_id.company_id', store=True, readonly=True, default=lambda self: self.env.company) company_currency_id = fields.Many2one(related='company_id.currency_id', string='Company Currency', readonly=True, store=True, help='Utility field to express amount currency') country_id = fields.Many2one(comodel_name='res.country', related='move_id.company_id.country_id') account_id = fields.Many2one('account.account', string='Account', index=True, ondelete="cascade", - domain=[('deprecated', '=', False)], + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + check_company=True, tracking=True) account_internal_type = fields.Selection(related='account_id.user_type_id.type', string="Internal Type", store=True, readonly=True) account_root_id = fields.Many2one(related='account_id.root_id', string="Account Root", store=True, readonly=True) @@ -2505,17 +2518,17 @@ class AccountMoveLine(models.Model): product_uom_category_id = fields.Many2one('uom.category', related='product_id.uom_id.category_id') # ==== Origin fields ==== - reconcile_model_id = fields.Many2one('account.reconcile.model', string="Reconciliation Model", copy=False, readonly=True) - payment_id = fields.Many2one('account.payment', string="Originator Payment", copy=False, + reconcile_model_id = fields.Many2one('account.reconcile.model', string="Reconciliation Model", copy=False, readonly=True, check_company=True) + payment_id = fields.Many2one('account.payment', string="Originator Payment", copy=False, check_company=True, help="Payment that created this entry") statement_line_id = fields.Many2one('account.bank.statement.line', string='Bank statement line reconciled with this entry', - index=True, copy=False, readonly=True) + index=True, copy=False, readonly=True, check_company=True) statement_id = fields.Many2one(related='statement_line_id.statement_id', store=True, index=True, copy=False, help="The bank statement used for bank reconciliation") # ==== Tax fields ==== - tax_ids = fields.Many2many('account.tax', string='Taxes', help="Taxes that apply on the base amount") + tax_ids = fields.Many2many('account.tax', string='Taxes', help="Taxes that apply on the base amount", check_company=True) tax_line_id = fields.Many2one('account.tax', string='Originator Tax', ondelete='restrict', store=True, compute='_compute_tax_line_id', help="Indicates that this journal item is a tax line") tax_group_id = fields.Many2one(related='tax_line_id.tax_group_id', string='Originator tax group', @@ -2529,6 +2542,7 @@ class AccountMoveLine(models.Model): " on taxes, some will become exigible only when the payment is recorded.") tax_repartition_line_id = fields.Many2one(comodel_name='account.tax.repartition.line', string="Originator Tax Repartition Line", ondelete='restrict', readonly=True, + check_company=True, help="Tax repartition line that caused the creation of this move line, if any") tax_tag_ids = fields.Many2many(string="Tags", comodel_name='account.account.tag', ondelete='restrict', help="Tags assigned to this line by the tax creating it, if any. It determines its impact on financial reports.", tracking=True) @@ -2552,8 +2566,8 @@ class AccountMoveLine(models.Model): # ==== Analytic fields ==== analytic_line_ids = fields.One2many('account.analytic.line', 'move_id', string='Analytic lines') - analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', index=True) - analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags') + analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', index=True, check_company=True) + analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', check_company=True) # ==== Onchange / display purpose fields ==== recompute_tax_line = fields.Boolean(store=False, readonly=True, diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 9b1ebce6160..58b479428cf 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -29,6 +29,7 @@ class account_payment(models.Model): _inherit = ['mail.thread', 'mail.activity.mixin'] _description = "Payments" _order = "payment_date desc, name desc" + _check_company_auto = True name = fields.Char(readonly=True, copy=False) # The name is attributed upon post() payment_reference = fields.Char(copy=False, readonly=True, help="Reference of the document used to issue this payment. Eg. check number, file name, etc.") @@ -73,9 +74,10 @@ class account_payment(models.Model): currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company.currency_id) payment_date = fields.Date(string='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='Journal', required=True, readonly=True, states={'draft': [('readonly', False)]}, tracking=True, domain="[('id', 'in', _suitable_journal_ids)]") + journal_id = fields.Many2one('account.journal', string='Journal', required=True, readonly=True, states={'draft': [('readonly', False)]}, tracking=True, + check_company=True, domain="[('id', 'in', _suitable_journal_ids)]") _suitable_journal_ids = fields.Many2many('account.journal', compute='_compute_suitable_journal_ids') - company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', readonly=True) + company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', readonly=True, store=True, default=lambda self: self.env.company) hide_payment_method = fields.Boolean(compute='_compute_hide_payment_method', help="Technical field used to hide the payment method if the " @@ -88,7 +90,7 @@ class account_payment(models.Model): string='Journal Item Label', help='Change label of the counterpart that will hold the payment difference', default='Write-Off') - partner_bank_account_id = fields.Many2one('res.partner.bank', string="Recipient Bank Account", readonly=True, states={'draft': [('readonly', False)]}, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id), ('partner_id', 'in', possible_bank_partner_ids)]") + partner_bank_account_id = fields.Many2one('res.partner.bank', string="Recipient Bank Account", readonly=True, states={'draft': [('readonly', False)]}, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id), ('partner_id', 'in', possible_bank_partner_ids)]", check_company=True) possible_bank_partner_ids = fields.Many2many('res.partner', compute='_compute_possible_bank_partners') show_partner_bank_account = fields.Boolean(compute='_compute_show_partner_bank', help='Technical field used to know whether the field `partner_bank_account_id` needs to be displayed or not in the payments form views') require_partner_bank_account = fields.Boolean(compute='_compute_show_partner_bank', help='Technical field used to know whether the field `partner_bank_account_id` needs to be required or not in the payments form views') diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 44d8f0e0535..96bc1553630 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -11,15 +11,20 @@ class AccountReconcileModelLine(models.Model): _name = 'account.reconcile.model.line' _description = 'Rules for the reconciliation model' _order = 'sequence, id' + _check_company_auto = True model_id = fields.Many2one('account.reconcile.model', readonly=True) match_total_amount = fields.Boolean(related='model_id.match_total_amount') match_total_amount_param = fields.Float(related='model_id.match_total_amount_param') rule_type = fields.Selection(related='model_id.rule_type') - company_id = fields.Many2one(related='model_id.company_id') + company_id = fields.Many2one(related='model_id.company_id', store=True, default=lambda self: self.env.company) sequence = fields.Integer(required=True, default=10) - account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', domain=[('deprecated', '=', False)], required=True) - journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.") + account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + required=True, check_company=True) + journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', + domain="[('type', '=', 'general'), ('company_id', '=', company_id)]", + help="This field is ignored in a bank statement reconciliation.", check_company=True) label = fields.Char(string='Journal Item Label') amount_type = fields.Selection([ ('fixed', 'Fixed'), @@ -33,9 +38,9 @@ class AccountReconcileModelLine(models.Model): * Percentage: Percentage of the balance, between 0 and 100. * Fixed: The fixed value of the writeoff. The amount will count as a debit if it is negative, as a credit if it is positive. * From Label: There is no need for regex delimiter, only the regex is needed. For instance if you want to extract the amount from\nR:9672938 10/07 AX 9415126318 T:5L:NA BRT: 3358,07 C:\nYou could enter\nBRT: ([\d,]+)""") - tax_ids = fields.Many2many('account.tax', string='Taxes', ondelete='restrict') - analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', ondelete='set null') - analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', + tax_ids = fields.Many2many('account.tax', string='Taxes', ondelete='restrict', check_company=True) + analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', ondelete='set null', check_company=True) + analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', check_company=True, relation='account_reconcile_model_analytic_tag_rel') @api.onchange('tax_ids') @@ -84,11 +89,15 @@ class AccountReconcileModel(models.Model): _name = 'account.reconcile.model' _description = 'Preset to create journal entries during a invoices and payments matching' _order = 'sequence, id' + _check_company_auto = True # Base fields. name = fields.Char(string='Name', required=True) sequence = fields.Integer(required=True, default=10) - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) + company_id = fields.Many2one( + comodel_name='res.company', + string='Company', required=True, readonly=True, + default=lambda self: self.env.company) rule_type = fields.Selection(selection=[ ('writeoff_button', 'Manually create a write-off on clicked button.'), @@ -101,7 +110,8 @@ class AccountReconcileModel(models.Model): # ===== Conditions ===== match_journal_ids = fields.Many2many('account.journal', string='Journals', - domain="[('type', 'in', ('bank', 'cash'))]", + domain="[('type', 'in', ('bank', 'cash')), ('company_id', '=', company_id)]", + check_company=True, help='The reconciliation model will only be available from the selected journals.') match_nature = fields.Selection(selection=[ ('amount_received', 'Amount Received'), diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 82934631012..f772c76ed73 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -22,7 +22,10 @@ class AccountFiscalPosition(models.Model): name = fields.Char(string='Fiscal Position', required=True) active = fields.Boolean(default=True, help="By unchecking the active field, you may hide a fiscal position without deleting it.") - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company, required=True) + company_id = fields.Many2one( + comodel_name='res.company', + string='Company', required=True, readonly=True, + default=lambda self: self.env.company) account_ids = fields.One2many('account.fiscal.position.account', 'position_id', string='Account Mapping', copy=True) tax_ids = fields.One2many('account.fiscal.position.tax', 'position_id', string='Tax Mapping', copy=True) note = fields.Text('Notes', translate=True, help="Legal mentions that have to be printed on the invoices.") @@ -191,11 +194,13 @@ class AccountFiscalPositionTax(models.Model): _name = 'account.fiscal.position.tax' _description = 'Tax Mapping of Fiscal Position' _rec_name = 'position_id' + _check_company_auto = True position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position', required=True, ondelete='cascade') - tax_src_id = fields.Many2one('account.tax', string='Tax on Product', required=True) - tax_dest_id = fields.Many2one('account.tax', string='Tax to Apply') + company_id = fields.Many2one('res.company', string='Company', related='position_id.company_id', store=True) + tax_src_id = fields.Many2one('account.tax', string='Tax on Product', required=True, check_company=True) + tax_dest_id = fields.Many2one('account.tax', string='Tax to Apply', check_company=True) _sql_constraints = [ ('tax_src_dest_uniq', @@ -208,13 +213,17 @@ class AccountFiscalPositionAccount(models.Model): _name = 'account.fiscal.position.account' _description = 'Accounts Mapping of Fiscal Position' _rec_name = 'position_id' + _check_company_auto = True position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position', required=True, ondelete='cascade') + company_id = fields.Many2one('res.company', string='Company', related='position_id.company_id', store=True) account_src_id = fields.Many2one('account.account', string='Account on Product', - domain=[('deprecated', '=', False)], required=True) + check_company=True, required=True, + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") account_dest_id = fields.Many2one('account.account', string='Account to Use Instead', - domain=[('deprecated', '=', False)], required=True) + check_company=True, required=True, + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") _sql_constraints = [ ('account_src_dest_uniq', @@ -393,23 +402,25 @@ class ResPartner(models.Model): journal_item_count = fields.Integer(compute='_compute_journal_item_count', string="Journal Items", type="integer") property_account_payable_id = fields.Many2one('account.account', company_dependent=True, string="Account Payable", - domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False)]", + domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", help="This account will be used instead of the default one as the payable account for the current partner", required=True) property_account_receivable_id = fields.Many2one('account.account', company_dependent=True, string="Account Receivable", - domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False)]", + domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", help="This account will be used instead of the default one as the receivable account for the current partner", required=True) property_account_position_id = fields.Many2one('account.fiscal.position', company_dependent=True, string="Fiscal Position", - domain="[('company_id', 'in', [company_id or current_company_id, False])]", + domain="[('company_id', '=', current_company_id)]", help="The fiscal position determines the taxes/accounts used for this contact.") property_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True, string='Customer Payment Terms', + domain="[('company_id', 'in', [current_company_id, False])]", help="This payment term will be used instead of the default one for sales orders and customer invoices") property_supplier_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True, string='Vendor Payment Terms', + domain="[('company_id', 'in', [current_company_id, False])]", help="This payment term will be used instead of the default one for purchase orders and vendor bills") ref_company_ids = fields.One2many('res.company', 'partner_id', string='Companies that refers to partner') diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index b1e2e8c5828..2a49bca8c42 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -567,6 +567,7 @@ <field name="move_type" invisible="1"/> <field name="payment_state" invisible="1" force_save="1"/> <field name="invoice_filter_type_domain" invisible="1"/> + <field name="suitable_journal_ids" invisible="1"/> <field name="company_currency_id" invisible="1"/> <field name="commercial_partner_id" invisible="1"/> <field name="bank_partner_id" invisible="1"/> @@ -645,7 +646,6 @@ invisible="context.get('default_journal_id') and context.get('move_type', 'entry') != 'entry'" groups="account.group_account_readonly" options="{'no_create': True}" - domain="[('type', '=?', invoice_filter_type_domain)]" attrs="{'readonly': [('posted_before', '=', True)]}"/> <field name="company_id" groups="base.group_multi_company"/> diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index f9257ad0dc6..60e322adff6 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -14,6 +14,7 @@ <div class="oe_title"> <h1 class= "oe_read_only"> <field name="code" placeholder="code"/> - <field name="name" placeholder="name"/> + <field name="company_id" invisible="1"/> </h1> <div class="oe_inline oe_edit_only"> <label for="code"/> @@ -290,8 +291,8 @@ <field name="refund_sequence" attrs="{'invisible': [('type', 'not in', ['sale', 'purchase'])]}"/> </group> <group> - <field name="default_debit_account_id" options="{'no_create': True}" domain="[('deprecated', '=', False)]" groups="account.group_account_readonly"/> - <field name="default_credit_account_id" options="{'no_create': True}" domain="[('deprecated', '=', False)]" groups="account.group_account_readonly"/> + <field name="default_debit_account_id" options="{'no_create': True}" groups="account.group_account_readonly"/> + <field name="default_credit_account_id" options="{'no_create': True}" groups="account.group_account_readonly"/> <field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/> </group> </group> @@ -644,6 +645,7 @@ action = model.setting_init_bank_account_action() <field name="amount_currency" optional="hidden"/> <field name="currency_id" optional="hidden"/> <field name="state" invisible="1"/> + <field name="company_id" invisible="1"/> <button name="button_cancel_reconciliation" attrs="{'invisible': ['|',('journal_entry_ids', '=', []), ('state', '=', 'confirm')]}" string="Revert reconciliation" type="object" icon="fa-undo"/> </tree> </field> @@ -732,6 +734,7 @@ action = model.setting_init_bank_account_action() <field name="sequence"/> <field name="note"/> <field name="transaction_type"/> + <field name="company_id" invisible="1"/> </group> </form> </field> @@ -886,14 +889,14 @@ action = model.setting_init_bank_account_action() <field name="show_decimal_separator" invisible="1"/> <field name="decimal_separator" attrs="{'invisible': [('show_decimal_separator', '=', False)]}" groups="base.group_no_one"/> </group> - <field name="line_ids" default="{'default_model_id': self}" nolabel="1"> + <field name="line_ids" default="{'default_model_id': self, 'default_company_id': self.company_id}" nolabel="1"> <tree editable="bottom"> <field name="account_id"/> <field name="amount_type"/> - <field name="journal_id" domain="[('type', '=', 'general'), ('company_id', '=', company_id)]" attrs="{'column_invisible': [('parent.rule_type', '!=', 'writeoff_button')]}"/> + <field name="journal_id" attrs="{'column_invisible': [('parent.rule_type', '!=', 'writeoff_button')]}"/> <field name="amount_string"/> <field name="tax_ids" widget="many2many_tags"/> - <field name="analytic_account_id" domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]" groups="analytic.group_analytic_tags"/> + <field name="analytic_account_id" groups="analytic.group_analytic_tags"/> <field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags"/> <field name="show_force_tax_included" invisible="1"/> <field name="force_tax_included" attrs="{'invisible': [('show_force_tax_included', '=', False)]}" widget="boolean_toggle"/> @@ -1073,7 +1076,7 @@ action = model.setting_init_bank_account_action() <field name="sequence" widget="handle"/> <field name="factor_percent" attrs="{'invisible': [('repartition_type', '=', 'base')]}"/> <field name="repartition_type"/> - <field name="account_id" attrs="{'invisible': [('repartition_type', '=', 'base')]}" options="{'no_create': True}" domain="[('internal_type', 'not in', ('receivable', 'payable'))]"/> + <field name="account_id" attrs="{'invisible': [('repartition_type', '=', 'base')]}" options="{'no_create': True}"/> <field name="tag_ids" widget="many2many_tags" options="{'no_create': True}" domain="[('applicability', '=', 'taxes'), ('country_id', '=', country_id)]"/> <field name="country_id" invisible="1"/> <field name="company_id" invisible="1"/> diff --git a/addons/account/wizard/account_accrual_accounting.py b/addons/account/wizard/account_accrual_accounting.py index 39bee5ea63c..84cde15d05d 100644 --- a/addons/account/wizard/account_accrual_accounting.py +++ b/addons/account/wizard/account_accrual_accounting.py @@ -8,7 +8,7 @@ class AccrualAccountingWizard(models.TransientModel): _description = 'Create accrual entry.' date = fields.Date(required=True) - company_id = fields.Many2one('res.company', required=True) + company_id = fields.Many2one('res.company', required=True, readonly=True) account_type = fields.Selection([('income', 'Revenue'), ('expense', 'Expense')]) active_move_line_ids = fields.Many2many('account.move.line') journal_id = fields.Many2one('account.journal', required=True, readonly=False, diff --git a/addons/account/wizard/account_move_reversal.py b/addons/account/wizard/account_move_reversal.py index 612c0d3cc29..836aad6e4ab 100644 --- a/addons/account/wizard/account_move_reversal.py +++ b/addons/account/wizard/account_move_reversal.py @@ -10,6 +10,7 @@ class AccountMoveReversal(models.TransientModel): """ _name = 'account.move.reversal' _description = 'Account Move Reversal' + _check_company_auto = True move_ids = fields.Many2many('account.move', 'account_move_reversal_move', 'reversal_id', 'move_id', domain=[('state', '=', 'posted')]) new_move_ids = fields.Many2many('account.move', 'account_move_reversal_new_move', 'reversal_id', 'new_move_id') @@ -21,7 +22,8 @@ class AccountMoveReversal(models.TransientModel): ('modify', 'Full refund and new draft invoice') ], string='Credit Method', required=True, help='Choose how you want to credit this invoice. You cannot "modify" nor "cancel" if the invoice is already reconciled.') - journal_id = fields.Many2one('account.journal', string='Use Specific Journal', help='If empty, uses the journal of the journal entry to be reversed.') + journal_id = fields.Many2one('account.journal', string='Use Specific Journal', help='If empty, uses the journal of the journal entry to be reversed.', check_company=True) + company_id = fields.Many2one('res.company', required=True, readonly=True) # computed fields residual = fields.Monetary(compute="_compute_from_moves") @@ -32,8 +34,10 @@ class AccountMoveReversal(models.TransientModel): def default_get(self, fields): res = super(AccountMoveReversal, self).default_get(fields) move_ids = self.env['account.move'].browse(self.env.context['active_ids']) if self.env.context.get('active_model') == 'account.move' else self.env['account.move'] + if any(move.state != "posted" for move in move_ids): raise UserError(_('You can only reverse posted moves.')) + res['company_id'] = move_ids.company_id.id or self.env.company.id res['move_ids'] = [(6, 0, move_ids.ids)] res['refund_method'] = (len(move_ids) > 1 or move_ids.move_type == 'entry') and 'cancel' or 'refund' return res diff --git a/addons/account/wizard/account_move_reversal_view.xml b/addons/account/wizard/account_move_reversal_view.xml index 00da1524720..674348ec6ca 100644 --- a/addons/account/wizard/account_move_reversal_view.xml +++ b/addons/account/wizard/account_move_reversal_view.xml @@ -7,6 +7,7 @@ <field name="arch" type="xml"> <form string="Reverse Journal Entry"> <field name="residual" invisible="1"/> + <field name="company_id" invisible="1"/> <field name="move_ids" invisible="1"/> <field name="move_type" invisible="1"/> <span class="text-muted" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'in_invoice', 'some_invoice'))]}">Invoices/>Bills won't be reversed but credit notes will be created instead: the tax tags will be adapted accordingly.</span> diff --git a/addons/account/wizard/setup_wizards.py b/addons/account/wizard/setup_wizards.py index 012c32f6ea7..d0f50da005a 100644 --- a/addons/account/wizard/setup_wizards.py +++ b/addons/account/wizard/setup_wizards.py @@ -67,10 +67,14 @@ class SetupBarBankConfigWizard(models.TransientModel): _inherits = {'res.partner.bank': 'res_partner_bank_id'} _name = 'account.setup.bank.manual.config' _description = 'Bank setup manual config' + _check_company_auto = True res_partner_bank_id = fields.Many2one(comodel_name='res.partner.bank', ondelete='cascade', required=True) new_journal_name = fields.Char(default=lambda self: self.linked_journal_id.name, inverse='set_linked_journal_id', required=True, help='Will be used to name the Journal related to this bank account') - linked_journal_id = fields.Many2one(string="Journal", comodel_name='account.journal', inverse='set_linked_journal_id', compute="_compute_linked_journal_id") + linked_journal_id = fields.Many2one(string="Journal", + comodel_name='account.journal', inverse='set_linked_journal_id', + compute="_compute_linked_journal_id", check_company=True, + domain="[('type','=','bank'), ('bank_account_id', '=', False), ('company_id', '=', company_id)]") new_journal_code = fields.Char(string="Code", required=True, default=lambda self: self._onchange_new_journal_code()) num_journals_without_account = fields.Integer(default=lambda self: self._number_unlinked_journal()) # field computing the type of the res.patrner.bank. It's behaves the same as a related res_part_bank_id.acc_type diff --git a/addons/account/wizard/setup_wizards_view.xml b/addons/account/wizard/setup_wizards_view.xml index 8e6c02f1e28..f6af2ceb31b 100644 --- a/addons/account/wizard/setup_wizards_view.xml +++ b/addons/account/wizard/setup_wizards_view.xml @@ -37,6 +37,7 @@ <form> <field name="num_journals_without_account" invisible="1"/> <field name="journal_id" invisible="1"/> + <field name="company_id" invisible="1"/> <field name="linked_journal_id" invisible="1"/> <sheet> <div class="oe_title"> @@ -54,7 +55,7 @@ </group> <group attrs="{'invisible': [('num_journals_without_account', '<', 2)]}"> <group> - <field name="linked_journal_id" attrs="{'required': [('num_journals_without_account','!=',0)]}" domain="[('type','=','bank'), ('bank_account_id', '=', False)]"/> + <field name="linked_journal_id" attrs="{'required': [('num_journals_without_account','!=',0)]}"/> </group> <group> <span class="text-muted">Only journals not yet linked to a bank account are proposed</span> @@ -76,6 +77,7 @@ <tree editable="top" create="1" delete="1" multi_edit="1" decoration-muted="opening_debit == 0 and opening_credit == 0"> <field name="code"/> <field name="name"/> + <field name="company_id" invisible="1"/> <field name="user_type_id"/> <field name="reconcile" widget="boolean_toggle"/> <field name="opening_debit"/> diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index e5fd1614f39..5c99a9dfcdf 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -59,6 +59,7 @@ class AccountAnalyticAccount(models.Model): _inherit = ['mail.thread'] _description = 'Analytic Account' _order = 'code, name asc' + _check_company_auto = True @api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): @@ -126,14 +127,14 @@ class AccountAnalyticAccount(models.Model): code = fields.Char(string='Reference', index=True, tracking=True) active = fields.Boolean('Active', help="If the active field is set to False, it will allow you to hide the account without removing it.", default=True) - group_id = fields.Many2one('account.analytic.group', string='Group', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + group_id = fields.Many2one('account.analytic.group', string='Group', check_company=True) line_ids = fields.One2many('account.analytic.line', 'account_id', string="Analytic Lines") company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) # use auto_join to speed up name_search call - partner_id = fields.Many2one('res.partner', string='Customer', auto_join=True, tracking=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + partner_id = fields.Many2one('res.partner', string='Customer', auto_join=True, tracking=True, check_company=True) balance = fields.Monetary(compute='_compute_debit_credit_balance', string='Balance') debit = fields.Monetary(compute='_compute_debit_credit_balance', string='Debit') @@ -172,6 +173,7 @@ class AccountAnalyticLine(models.Model): _name = 'account.analytic.line' _description = 'Analytic Line' _order = 'date desc, id desc' + _check_company_auto = True @api.model def _default_user(self): @@ -183,10 +185,10 @@ class AccountAnalyticLine(models.Model): unit_amount = fields.Float('Quantity', default=0.0) product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure', domain="[('category_id', '=', product_uom_category_id)]") product_uom_category_id = fields.Many2one(related='product_uom_id.category_id', readonly=True) - account_id = fields.Many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', index=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") - partner_id = fields.Many2one('res.partner', string='Partner', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + account_id = fields.Many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', index=True, check_company=True) + partner_id = fields.Many2one('res.partner', string='Partner', check_company=True) 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, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_line_tag_rel', 'line_id', 'tag_id', string='Tags', copy=True, check_company=True) company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True, store=True, compute_sudo=True) group_id = fields.Many2one('account.analytic.group', related='account_id.group_id', store=True, readonly=True, compute_sudo=True) diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index f1bb6ba1101..8d0601b0c96 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -139,8 +139,8 @@ class TestPointOfSaleCommon(StockAccountTestCommon): {'taxes_id': [(6, 0, [account_tax_05_incl.id, account_tax_05_incl_chicago.id])]}) # Set account_id in the generated repartition lines. Automatically, nothing is set. - invoice_rep_lines = (account_tax_05_incl | account_tax_05_incl_chicago | account_tax_10_incl).mapped('invoice_repartition_line_ids') - refund_rep_lines = (account_tax_05_incl | account_tax_05_incl_chicago | account_tax_10_incl).mapped('refund_repartition_line_ids') + invoice_rep_lines = (account_tax_05_incl | account_tax_10_incl).mapped('invoice_repartition_line_ids') + refund_rep_lines = (account_tax_05_incl | account_tax_10_incl).mapped('refund_repartition_line_ids') # Expense account, should just be something else than receivable/payable (invoice_rep_lines | refund_rep_lines).write({'account_id': cls.a_expense.id}) |
