From cf9b17a85543ae893538ae8b5d2d0829978288d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 29 Aug 2014 16:15:15 +0200 Subject: [PATCH] Raise error for account used only on the accessor Because of the batch mode of Function field, the getter must not raise error otherwise the error can be raised for a record that doesn't require the account. So we introduce an new kind of Function field which raise the error only at the accessor level. issue4087 review9531002 --- product.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/product.py b/product.py index 1ea06dab8d..8d5ef303f7 100644 --- a/product.py +++ b/product.py @@ -4,6 +4,8 @@ from trytond.model import fields from trytond.pyson import Eval from trytond.pool import PoolMeta +from trytond.modules.account_product import MissingFunction + __all__ = ['Category', 'Template'] __metaclass__ = PoolMeta @@ -20,8 +22,9 @@ class Category: | Eval('account_parent')), }, depends=['account_parent'])) - account_cogs_used = fields.Function(fields.Many2One('account.account', - 'Account Cost of Goods Sold Used'), 'get_account') + account_cogs_used = MissingFunction(fields.Many2One('account.account', + 'Account Cost of Goods Sold Used'), 'missing_account', + 'get_account') class Template: @@ -39,5 +42,6 @@ class Template: help='This account will be used instead of the one defined ' 'on the category.', depends=['account_category', 'type'])) - account_cogs_used = fields.Function(fields.Many2One('account.account', - 'Account Cost of Goods Sold Used'), 'get_account') + account_cogs_used = MissingFunction(fields.Many2One('account.account', + 'Account Cost of Goods Sold Used'), 'missing_account', + 'get_account')