Add number as record name to payment

Closes #7285
This commit is contained in:
Cédric Krier
2024-10-13 14:44:08 +02:00
parent 07902c1f81
commit 39ae838bfe
9 changed files with 98 additions and 4 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add number as record name to payment
* Add payment amount cache to account move line
* Add option to create direct debit based on balance
* Enforce payment amount to be greater or equal to zero
+1
View File
@@ -15,6 +15,7 @@ def register():
account.PayLineStart,
account.PayLineAskJournal,
account.Configuration,
account.ConfigurationPaymentSequence,
account.ConfigurationPaymentGroupSequence,
party.Party,
party.PartyPaymentDirectDebit,
+36
View File
@@ -559,6 +559,15 @@ class PayLine(Wizard):
class Configuration(metaclass=PoolMeta):
__name__ = 'account.configuration'
payment_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Payment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('account_payment',
'sequence_type_account_payment')),
]))
payment_group_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', 'Payment Group Sequence', required=True,
domain=[
@@ -569,12 +578,39 @@ class Configuration(metaclass=PoolMeta):
'sequence_type_account_payment_group')),
]))
@classmethod
def default_payment_sequence(cls, **pattern):
return cls.multivalue_model(
'payment_sequence').default_payment_sequence()
@classmethod
def default_payment_group_sequence(cls, **pattern):
return cls.multivalue_model(
'payment_group_sequence').default_payment_group_sequence()
class ConfigurationPaymentSequence(ModelSQL, CompanyValueMixin):
"Account Configuration Payment Sequence"
__name__ = 'account.configuration.payment_sequence'
payment_sequence = fields.Many2One(
'ir.sequence', "Payment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('account_payment', 'sequence_type_account_payment')),
])
@classmethod
def default_payment_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id(
'account_payment', 'sequence_account_payment')
except KeyError:
return None
class ConfigurationPaymentGroupSequence(ModelSQL, CompanyValueMixin):
"Account Configuration Payment Group Sequence"
__name__ = 'account.configuration.payment_group_sequence'
+31
View File
@@ -273,6 +273,8 @@ _STATES = {
class Payment(Workflow, ModelSQL, ModelView):
'Payment'
__name__ = 'account.payment'
_rec_name = 'number'
number = fields.Char("Number", required=True, readonly=True)
company = fields.Many2One(
'company.company', "Company", required=True, states=_STATES)
journal = fields.Many2One('account.payment.journal', 'Journal',
@@ -459,6 +461,24 @@ class Payment(Workflow, ModelSQL, ModelView):
readonly=False, instantiate=0, fresh_session=True),
})
@classmethod
def __register__(cls, module):
cursor = Transaction().connection.cursor()
table = cls.__table__()
table_h = cls.__table_handler__(module)
number_exist = table_h.column_exist('number')
super().__register__(module)
# Migration from 7.2: add number
if not number_exist:
cursor.execute(*table.update([table.number], [table.id]))
@classmethod
def order_number(cls, tables):
table, _ = tables[None]
return [CharLength(table.number), table.number]
@staticmethod
def default_company():
return Transaction().context.get('company')
@@ -553,6 +573,7 @@ class Payment(Workflow, ModelSQL, ModelView):
default = {}
else:
default = default.copy()
default.setdefault('number', None)
default.setdefault('group', None)
default.setdefault('approved_by')
default.setdefault('succeeded_by')
@@ -563,6 +584,16 @@ class Payment(Workflow, ModelSQL, ModelView):
def create(cls, vlist):
pool = Pool()
Line = pool.get('account.move.line')
Config = pool.get('account.configuration')
vlist = [v.copy() for v in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'payment_sequence',
company=values.get('company', default_company)).get()
payments = super().create(vlist)
lines = {p.line for p in payments if p.line}
if lines:
+17
View File
@@ -544,6 +544,23 @@ this repository contains the full copyright notices and license terms. -->
<field name="string">Fail</field>
</record>
<record model="ir.sequence.type" id="sequence_type_account_payment">
<field name="name">Account Payment Group</field>
</record>
<record model="ir.sequence.type-res.group" id="sequence_type_account_payment_group_admin">
<field name="sequence_type" ref="sequence_type_account_payment"/>
<field name="group" ref="res.group_admin"/>
</record>
<record model="ir.sequence.type-res.group" id="sequence_type_account_payment_group_account_admin">
<field name="sequence_type" ref="sequence_type_account_payment"/>
<field name="group" ref="account.group_account_admin"/>
</record>
<record model="ir.sequence" id="sequence_account_payment">
<field name="name">Default Account Payment</field>
<field name="sequence_type" ref="sequence_type_account_payment"/>
</record>
<record model="ir.action.wizard" id="act_process_payments">
<field name="name">Process Payments</field>
<field name="wiz_name">account.payment.process</field>
@@ -83,6 +83,8 @@ Partially pay line::
>>> assertEqual(pay_line.form.journal, payment_journal)
>>> pay_line.execute('next_')
>>> payment, = Payment.find()
>>> bool(payment.number)
True
>>> assertEqual(payment.date, tomorrow)
>>> assertEqual(payment.party, supplier)
>>> payment.amount
@@ -4,7 +4,9 @@ this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form" position="inside">
<separator id="payment" string="Payment" colspan="4"/>
<label name="payment_group_sequence" string="Group Sequence"/>
<label name="payment_sequence" string="Sequence:"/>
<field name="payment_sequence"/>
<label name="payment_group_sequence" string="Group Sequence:"/>
<field name="payment_group_sequence"/>
<newline/>
</xpath>
@@ -1,7 +1,12 @@
<?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. -->
<form>
<form cursor="journal">
<label name="number"/>
<field name="number"/>
<label name="company"/>
<field name="company"/>
<label name="journal"/>
<field name="journal" widget="selection"/>
<label name="kind"/>
@@ -20,8 +25,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="description" colspan="3"/>
</page>
<page string="Other Info" id="info">
<label name="company"/>
<field name="company"/>
<label name="group"/>
<field name="group"/>
<label name="origin"/>
@@ -2,6 +2,7 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="number"/>
<field name="journal" expand="1" optional="0"/>
<field name="kind" optional="0"/>
<field name="party" expand="2" optional="0"/>