Add default customer payment term configuration

issue9855
review318881002
This commit is contained in:
Cédric Krier committed 2020-12-23 21:46:51 +01:00
1 parent f4749bdd9e
commit 1062a7bebb
7 files changed
+59 -18

No files matched your search

+2
View File
@@ -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
+2
View File
@@ -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
+25
View File
@@ -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'
+6
View File
@@ -8,6 +8,12 @@ this repository contains the full copyright notices and license terms. -->
<field name="path">icons/tryton-invoice.svg</field>
</record>
<record model="ir.ui.view" id="configuration_view_form">
<field name="model">account.configuration</field>
<field name="inherit" ref="account.configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
<record model="ir.ui.view" id="fiscalyear_view_form">
<field name="model">account.fiscalyear</field>
<field name="inherit" ref="account.fiscalyear_view_form"/>
+5 -18
View File
@@ -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):
+9
View File
@@ -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"
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='default_account_payable']" position="after">
<label name="default_customer_payment_term"/>
<field name="default_customer_payment_term"/>
<newline/>
</xpath>
</data>