Skip to content
Permalink
Browse files

[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.
  • Loading branch information...
william-andre committed Sep 18, 2019
1 parent 6839671 commit d066e2a837223fe3ceea866195709595d86f92b3
@@ -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 @@ def setUpAccountJournal(cls):
'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 @@ def test_00_purchase_order_report(self):
})
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()
@@ -216,17 +216,14 @@ def test_no_expense(self):
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")
@@ -184,7 +184,6 @@ def test_cost_invoicing(self):
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, {

0 comments on commit d066e2a

Please sign in to comment.
You can’t perform that action at this time.