changeset da277943635d in modules/account_invoice:default
details:
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=da277943635d
description:
Add default customer payment term configuration
issue9855
review318881002
diffstat:
CHANGELOG | 2 ++
__init__.py | 2 ++
account.py | 25 +++++++++++++++++++++++++
account.xml | 6 ++++++
invoice.py | 23 +++++------------------
party.py | 9 +++++++++
view/configuration_form.xml | 10 ++++++++++
7 files changed, 59 insertions(+), 18 deletions(-)
diffs (150 lines):
diff -r e7d459f81e94 -r da277943635d CHANGELOG
--- a/CHANGELOG Sat Dec 19 17:08:44 2020 +0100
+++ b/CHANGELOG Wed Dec 23 21:46:51 2020 +0100
@@ -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 -r e7d459f81e94 -r da277943635d __init__.py
--- a/__init__.py Sat Dec 19 17:08:44 2020 +0100
+++ b/__init__.py Wed Dec 23 21:46:51 2020 +0100
@@ -28,6 +28,8 @@
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 -r e7d459f81e94 -r da277943635d account.py
--- a/account.py Sat Dec 19 17:08:44 2020 +0100
+++ b/account.py Wed Dec 23 21:46:51 2020 +0100
@@ -12,6 +12,31 @@
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 -r e7d459f81e94 -r da277943635d account.xml
--- a/account.xml Sat Dec 19 17:08:44 2020 +0100
+++ b/account.xml Wed Dec 23 21:46:51 2020 +0100
@@ -8,6 +8,12 @@
<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"/>
diff -r e7d459f81e94 -r da277943635d invoice.py
--- a/invoice.py Sat Dec 19 17:08:44 2020 +0100
+++ b/invoice.py Wed Dec 23 21:46:51 2020 +0100
@@ -410,23 +410,6 @@
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 @@
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 -r e7d459f81e94 -r da277943635d party.py
--- a/party.py Sat Dec 19 17:08:44 2020 +0100
+++ b/party.py Wed Dec 23 21:46:51 2020 +0100
@@ -45,6 +45,15 @@
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 -r e7d459f81e94 -r da277943635d view/configuration_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/configuration_form.xml Wed Dec 23 21:46:51 2020 +0100
@@ -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>