[FIX] account: constraint on empty account

If SQL, if you do
```display_type IN ('line_section', 'line_note') OR account_id IS NOT NULL```
and `display_type` is `NULL` then you can only have `'t'` because
`SELECT NULL OR 'f';` yields `NULL`
`SELECT NULL OR 't';` yields `'t'`
The check of NULL is not blocking, hence the constraint doesn't work.

closes odoo/odoo#37075

Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
wan
2019-09-20 13:59:21 +00:00
parent e41f468972
commit d3ddcc613f
5 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -2278,7 +2278,7 @@ class AccountMoveLine(models.Model):
),
(
'check_accountable_required_fields',
"CHECK(display_type IN ('line_section', 'line_note') OR account_id IS NOT NULL)",
"CHECK(COALESCE(display_type IN ('line_section', 'line_note'), 'f') OR account_id IS NOT NULL)",
"Missing required account on accountable invoice line."
),
(
@@ -83,12 +83,16 @@ class TestAccountNoChartCommon(SavepointCase):
'code': 'AJ-PURC',
'type': 'purchase',
'company_id': cls.env.user.company_id.id,
'default_debit_account_id': cls.account_expense.id,
'default_credit_account_id': cls.account_expense.id,
})
cls.journal_sale = cls.env['account.journal'].create({
'name': 'Sale Journal - Test',
'code': 'AJ-SALE',
'type': 'sale',
'company_id': cls.env.user.company_id.id,
'default_debit_account_id': cls.account_income.id,
'default_credit_account_id': cls.account_income.id,
})
@classmethod
@@ -56,7 +56,7 @@ class TestPurchaseOrderReport(common.TransactionCase):
})
po.button_confirm()
f = Form(self.env['account.move'])
f = Form(self.env['account.move'].with_context(default_type='in_invoice'))
f.partner_id = po.partner_id
f.purchase_id = po
invoice = f.save()
+8 -11
View File
@@ -216,17 +216,14 @@ class TestReInvoice(TestCommonSaleNoChart):
self.sale_order.action_confirm()
# create invoice lines and validate it
invoice_a = self.AccountMove.create({
'partner_id': self.partner_customer_usd.id,
'journal_id': self.journal_purchase.id,
'line_ids': [
(0, 0, {
'product_id': self.product_no_expense.id,
'quantity': 3,
'analytic_account_id': self.analytic_account.id,
}),
],
})
move_form = Form(self.AccountMove)
move_form.partner_id = self.partner_customer_usd
move_form.journal_id = self.journal_purchase
with move_form.line_ids.new() as line_form:
line_form.product_id = self.product_no_expense
line_form.quantity = 3.0
line_form.analytic_account_id = self.analytic_account
invoice_a = move_form.save()
invoice_a.post()
self.assertEquals(len(self.sale_order.order_line), 1, "No SO line should have been created (or removed) when validating vendor bill")
-1
View File
@@ -184,7 +184,6 @@ class TestSaleOrder(TestCommonSaleNoChart):
so._create_analytic_account()
inv = self.env['account.move'].with_context(default_type='in_invoice').create({
'type': 'in_invoice',
'partner_id': self.partner_customer_usd.id,
'invoice_line_ids': [
(0, 0, {