changeset 64c2dc298949 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset;node=64c2dc298949
description:
        Add default customer and supplier tax rule

        issue8542
        review267741002
diffstat:

 CHANGELOG                   |   1 +
 __init__.py                 |   9 +++++----
 configuration.py            |  37 +++++++++++++++++++++++++++++++++++--
 party.py                    |  18 ++++++++++++++++++
 view/configuration_form.xml |   4 ++++
 5 files changed, 63 insertions(+), 6 deletions(-)

diffs (151 lines):

diff -r 590c09935000 -r 64c2dc298949 CHANGELOG
--- a/CHANGELOG Fri Aug 09 16:32:31 2019 +0200
+++ b/CHANGELOG Sun Aug 18 19:06:19 2019 +0200
@@ -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 -r 590c09935000 -r 64c2dc298949 __init__.py
--- a/__init__.py       Fri Aug 09 16:32:31 2019 +0200
+++ b/__init__.py       Sun Aug 18 19:06:19 2019 +0200
@@ -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 @@
         UpdateChartSucceed,
         AgedBalanceContext,
         AgedBalance,
-        Configuration,
-        ConfigurationDefaultAccount,
+        configuration.Configuration,
+        configuration.ConfigurationDefaultAccount,
+        configuration.DefaultTaxRule,
         Period,
         Journal,
         JournalSequence,
@@ -48,7 +49,7 @@
         JournalPeriod,
         Move,
         Reconciliation,
-        ConfigurationTaxRounding,
+        configuration.ConfigurationTaxRounding,
         Line,
         WriteOff,
         OpenJournalAsk,
diff -r 590c09935000 -r 64c2dc298949 configuration.py
--- a/configuration.py  Fri Aug 09 16:32:31 2019 +0200
+++ b/configuration.py  Sun Aug 18 19:06:19 2019 +0200
@@ -7,8 +7,6 @@
 from trytond.modules.company.model import (
     CompanyMultiValueMixin, CompanyValueMixin)
 
-__all__ = ['Configuration', 'ConfigurationDefaultAccount',
-    'ConfigurationTaxRounding']
 tax_roundings = [
     ('document', 'Per Document'),
     ('line', 'Per Line'),
@@ -33,6 +31,20 @@
                 ('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 @@
         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 @@
         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 -r 590c09935000 -r 64c2dc298949 party.py
--- a/party.py  Fri Aug 09 16:32:31 2019 +0200
+++ b/party.py  Sun Aug 18 19:06:19 2019 +0200
@@ -94,6 +94,24 @@
         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()
         Company = pool.get('company.company')
diff -r 590c09935000 -r 64c2dc298949 view/configuration_form.xml
--- a/view/configuration_form.xml       Fri Aug 09 16:32:31 2019 +0200
+++ b/view/configuration_form.xml       Sun Aug 18 19:06:19 2019 +0200
@@ -8,6 +8,10 @@
     <label name="default_account_payable"/>
     <field name="default_account_payable"/>
     <separator id="invoice" string="Invoice" colspan="4"/>
+    <label name="default_customer_tax_rule"/>
+    <field name="default_customer_tax_rule"/>
+    <label name="default_supplier_tax_rule"/>
+    <field name="default_supplier_tax_rule"/>
     <label name="tax_rounding"/>
     <field name="tax_rounding"/>
 </form>

Reply via email to