diff --git a/CHANGELOG b/CHANGELOG
index 9da2034a49..75fe797a09 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add default customer payment term configuration
+
Version 5.8.0 - 2020-11-02
* Bug fixes (see mercurial logs for details)
* Remove support for Python 3.5
diff --git a/__init__.py b/__init__.py
index cd412407db..f0d87444a0 100644
--- a/__init__.py
+++ b/__init__.py
@@ -28,6 +28,8 @@ def register():
party.ContactMechanism,
party.Party,
party.PartyPaymentTerm,
+ account.Configuration,
+ account.ConfigurationDefaultPaymentTerm,
account.InvoiceSequence,
# Match pattern migration fallbacks to Fiscalyear values so Period
# must be registered before Fiscalyear
diff --git a/account.py b/account.py
index 5d7f086958..43ed009588 100644
--- a/account.py
+++ b/account.py
@@ -12,6 +12,31 @@ from trytond.pool import Pool, PoolMeta
from trytond.tools import grouped_slice
from trytond.transaction import Transaction
+from trytond.modules.company.model import CompanyValueMixin
+
+
+class Configuration(metaclass=PoolMeta):
+ __name__ = 'account.configuration'
+
+ default_customer_payment_term = fields.MultiValue(
+ fields.Many2One(
+ 'account.invoice.payment_term', "Default Customer Payment Term"))
+
+ @classmethod
+ def multivalue_model(cls, field):
+ pool = Pool()
+ if field in 'default_customer_payment_term':
+ return pool.get('account.configuration.default_payment_term')
+ return super().multivalue_model(field)
+
+
+class ConfigurationDefaultPaymentTerm(ModelSQL, CompanyValueMixin):
+ "Account Configuration Default Payment Term"
+ __name__ = 'account.configuration.default_payment_term'
+
+ default_customer_payment_term = fields.Many2One(
+ 'account.invoice.payment_term', "Default Customer Payment Term")
+
class FiscalYear(metaclass=PoolMeta):
__name__ = 'account.fiscalyear'
diff --git a/account.xml b/account.xml
index 1113b9596a..0a3edc778f 100644
--- a/account.xml
+++ b/account.xml
@@ -8,6 +8,12 @@ this repository contains the full copyright notices and license terms. -->
icons/tryton-invoice.svg
+
+ account.configuration
+
+ configuration_form
+
+
account.fiscalyear
diff --git a/invoice.py b/invoice.py
index 673d4227d0..06a20b6913 100644
--- a/invoice.py
+++ b/invoice.py
@@ -410,23 +410,6 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
if self.company:
return self.company.party.id
- @classmethod
- def default_payment_term(cls):
- PaymentTerm = Pool().get('account.invoice.payment_term')
- payment_terms = PaymentTerm.search(cls.payment_term.domain)
- if len(payment_terms) == 1:
- return payment_terms[0].id
-
- @fields.depends('party', 'type')
- def on_change_with_payment_term(self):
- payment_term = None
- if self.party:
- if self.type == 'out':
- payment_term = self.party.customer_payment_term
- elif self.type == 'in':
- payment_term = self.party.supplier_payment_term
- return payment_term.id if payment_term else None
-
@fields.depends('party', 'type', 'accounting_date', 'invoice_date')
def on_change_with_account(self):
account = None
@@ -459,12 +442,16 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
else:
return ['expense']
- @fields.depends('party')
+ @fields.depends('party', 'type')
def on_change_party(self):
self.invoice_address = None
if self.party:
self.invoice_address = self.party.address_get(type='invoice')
self.party_tax_identifier = self.party.tax_identifier
+ if self.type == 'out':
+ self.payment_term = self.party.customer_payment_term
+ elif self.type == 'in':
+ self.payment_term = self.party.supplier_payment_term
@fields.depends('currency')
def on_change_with_currency_digits(self, name=None):
diff --git a/party.py b/party.py
index 562dedf40f..7e7bd41941 100644
--- a/party.py
+++ b/party.py
@@ -45,6 +45,15 @@ class Party(ModelSQL, ModelView):
return pool.get('party.party.payment_term')
return super(Party, cls).multivalue_model(field)
+ @classmethod
+ def default_customer_payment_term(cls, **pattern):
+ pool = Pool()
+ Configuration = pool.get('account.configuration')
+ config = Configuration(1)
+ payment_term = config.get_multivalue(
+ 'default_customer_payment_term', **pattern)
+ return payment_term.id if payment_term else None
+
class PartyPaymentTerm(ModelSQL, ValueMixin):
"Party Payment Term"
diff --git a/view/configuration_form.xml b/view/configuration_form.xml
new file mode 100644
index 0000000000..19df0c4dd0
--- /dev/null
+++ b/view/configuration_form.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+