From 74ce1bacd54fed074e76fa0a55bad318ceb0a2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 18 Aug 2019 19:06:19 +0200 Subject: [PATCH] Add default customer and supplier tax rule issue8542 review267741002 --- CHANGELOG | 1 + __init__.py | 9 +++++---- configuration.py | 37 +++++++++++++++++++++++++++++++++++-- party.py | 18 ++++++++++++++++++ view/configuration_form.xml | 4 ++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fb49a86ed4..51c95922f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add default customer and supplier tax rule * Update sequence name in renew fiscal year * Make tax required on tax line * Use today as default date when inside the period diff --git a/__init__.py b/__init__.py index 94478d9355..eb5da34651 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ from trytond.pool import Pool from .fiscalyear import * from .account import * -from .configuration import * +from . import configuration from .period import * from .journal import * from .move import * @@ -39,8 +39,9 @@ def register(): UpdateChartSucceed, AgedBalanceContext, AgedBalance, - Configuration, - ConfigurationDefaultAccount, + configuration.Configuration, + configuration.ConfigurationDefaultAccount, + configuration.DefaultTaxRule, Period, Journal, JournalSequence, @@ -48,7 +49,7 @@ def register(): JournalPeriod, Move, Reconciliation, - ConfigurationTaxRounding, + configuration.ConfigurationTaxRounding, Line, WriteOff, OpenJournalAsk, diff --git a/configuration.py b/configuration.py index 4b23f2e109..14deae6026 100644 --- a/configuration.py +++ b/configuration.py @@ -7,8 +7,6 @@ from trytond.pyson import Eval from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) -__all__ = ['Configuration', 'ConfigurationDefaultAccount', - 'ConfigurationTaxRounding'] tax_roundings = [ ('document', 'Per Document'), ('line', 'Per Line'), @@ -33,6 +31,20 @@ class Configuration( ('party_required', '=', True), ('company', '=', Eval('context', {}).get('company', -1)), ])) + default_customer_tax_rule = fields.MultiValue(fields.Many2One( + 'account.tax.rule', "Default Customer Tax Rule", + domain=[ + ('company', '=', Eval('context', {}).get('company', -1)), + ('kind', 'in', ['sale', 'both']), + ]), + help="Default customer tax rule for new parties.") + default_supplier_tax_rule = fields.MultiValue(fields.Many2One( + 'account.tax.rule', "Default Supplier Tax Rule", + domain=[ + ('company', '=', Eval('context', {}).get('company', -1)), + ('kind', 'in', ['purchase', 'both']), + ]), + help="Default supplier tax rule for new parties.") tax_rounding = fields.MultiValue(fields.Selection( tax_roundings, "Tax Rounding")) @@ -41,6 +53,8 @@ class Configuration( pool = Pool() if field in {'default_account_receivable', 'default_account_payable'}: return pool.get('account.configuration.default_account') + if field in {'default_customer_tax_rule', 'default_supplier_tax_rule'}: + return pool.get('account.configuration.default_tax_rule') return super(Configuration, cls).multivalue_model(field) @classmethod @@ -69,6 +83,25 @@ class ConfigurationDefaultAccount(ModelSQL, CompanyValueMixin): depends=['company']) +class DefaultTaxRule(ModelSQL, CompanyValueMixin): + "Account Configuration Default Tax Rule" + __name__ = 'account.configuration.default_tax_rule' + default_customer_tax_rule = fields.Many2One( + 'account.tax.rule', "Default Customer Tax Rule", + domain=[ + ('company', '=', Eval('company', -1)), + ('kind', 'in', ['sale', 'both']), + ], + depends=['company']) + default_supplier_tax_rule = fields.Many2One( + 'account.tax.rule', "Default Supplier Tax Rule", + domain=[ + ('company', '=', Eval('company', -1)), + ('kind', 'in', ['purchase', 'both']), + ], + depends=['company']) + + class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin): 'Account Configuration Tax Rounding' __name__ = 'account.configuration.tax_rounding' diff --git a/party.py b/party.py index fd6b807077..0f7e23121f 100644 --- a/party.py +++ b/party.py @@ -93,6 +93,24 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta): return pool.get('party.party.account') return super(Party, cls).multivalue_model(field) + @classmethod + def _default_tax_rule(cls, type_, **pattern): + pool = Pool() + Configuration = pool.get('account.configuration') + config = Configuration(1) + assert type_ in {'customer', 'supplier'} + tax_rule = config.get_multivalue( + 'default_%s_tax_rule' % type_, **pattern) + return tax_rule.id if tax_rule else None + + @classmethod + def default_customer_tax_rule(cls, **pattern): + return cls._default_tax_rule('customer', **pattern) + + @classmethod + def default_supplier_tax_rule(cls, **pattern): + return cls._default_tax_rule('supplier', **pattern) + @classmethod def get_currency_digits(cls, parties, name): pool = Pool() diff --git a/view/configuration_form.xml b/view/configuration_form.xml index cbeb940bb1..3b81b1295c 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -8,6 +8,10 @@ this repository contains the full copyright notices and license terms. -->