[FIX] account_check_printing: do not set account_check_printing_layout as required

Adding required fields on company model is annoying for tests. Indeed multi
company tests may run during module installation, notably in CRM. Those tests
generally require to create a new company which is not possible if the column
is required but module not already loaded in registry. This is the case
if for example account_invoice_extract is installed and updating CRM
when testing website_crm_score.

When possible, avoid required fields on a such used model as company. In this
case we simply make the field required in the view, and handle a void value
as the default disabled one, leading to no functional change.

closes odoo/odoo#48059

Related: odoo/enterprise#9381
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2020-03-19 17:13:30 +00:00
parent 86691b1379
commit 215b2fffa2
3 changed files with 5 additions and 5 deletions
@@ -110,7 +110,7 @@ class AccountPayment(models.Model):
def do_print_checks(self):
check_layout = self[0].company_id.account_check_printing_layout
if check_layout == 'disabled':
if not check_layout or check_layout == 'disabled':
raise UserError(_("You have to choose a check layout. For this, go in Invoicing/Accounting Settings, search for 'Checks layout' and set one."))
report_action = self.env.ref(check_layout, False)
if not report_action:
@@ -118,7 +118,6 @@ class AccountPayment(models.Model):
self.write({'state': 'sent'})
return report_action.report_action(self)
def set_check_amount_in_words(self):
for payment in self:
payment.check_amount_in_words = payment.currency_id.amount_to_text(payment.amount) if payment.currency_id else ''
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
from odoo import models, api, fields
from odoo import models, fields
class res_company(models.Model):
_inherit = "res.company"
# This field needs to be overridden with `selection_add` in the modules which intends to add report layouts.
# The xmlID of all the report actions which are actually Check Layouts has to be kept as key of the selection.
account_check_printing_layout = fields.Selection(string="Check Layout", required=True,
account_check_printing_layout = fields.Selection(string="Check Layout",
help="Select the format corresponding to the check paper you will be printing your checks on.\n"
"In order to disable the printing feature, select 'None'.",
selection=[
@@ -9,7 +9,7 @@
<div class="content-group">
<div class="row mt16">
<label for="account_check_printing_layout" class="col-lg-4 o_light_label"/>
<field name="account_check_printing_layout"/>
<field name="account_check_printing_layout" required="True"/>
</div>
<div class="row">
<label for="account_check_printing_multi_stub" class="col-lg-4 o_light_label"/>