[FIX] account: don't allow to user remove the company
When a user creates a journal entry in accounting and the company is empty or
not selected in that journal entry, an error is generated.
step to reproduce -
- install the `Invoicing` & `Inventory`.
- open the `Invoicing`.
- create New.
- open `other info` note page > company (company_id) must be empty.
- the error will be generated.
Error-ValueError:
Expected singleton: res. company()
If the user attempts to remove the company after this commit, they get a
validation error.
sentry-4558397052
closes odoo/odoo#144982
X-original-commit: baa6153bd25a794f432e1a8665098479b33b6e8e
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
@@ -11947,6 +11947,15 @@ msgstr ""
|
||||
msgid "Select specific invoice and delivery addresses"
|
||||
msgstr ""
|
||||
|
||||
#. module: account
|
||||
#. odoo-python
|
||||
#: code:addons/account/models/account_move.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"We can't leave this document without any company. Please select a company "
|
||||
"for this document."
|
||||
msgstr ""
|
||||
|
||||
#. module: account
|
||||
#: model_terms:ir.ui.view,arch_db:account.res_config_settings_view_form
|
||||
msgid ""
|
||||
|
||||
@@ -1668,6 +1668,11 @@ class AccountMove(models.Model):
|
||||
|
||||
@api.onchange('company_id')
|
||||
def _inverse_company_id(self):
|
||||
for move in self:
|
||||
# This can't be caught by a python constraint as it is only triggered at save and the compute method that
|
||||
# needs this data to be set correctly before saving
|
||||
if not move.company_id:
|
||||
raise ValidationError(_("We can't leave this document without any company. Please select a company for this document."))
|
||||
self._conditional_add_to_compute('journal_id', lambda m: (
|
||||
not m.journal_id.filtered_domain(self.env['account.journal']._check_company_domain(m.company_id))
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user