diff --git a/modules/account_payment/CHANGELOG b/modules/account_payment/CHANGELOG index d323144641..17cab30336 100644 --- a/modules/account_payment/CHANGELOG +++ b/modules/account_payment/CHANGELOG @@ -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 diff --git a/modules/account_payment/__init__.py b/modules/account_payment/__init__.py index 7f55a36d70..5f33920022 100644 --- a/modules/account_payment/__init__.py +++ b/modules/account_payment/__init__.py @@ -15,6 +15,7 @@ def register(): account.PayLineStart, account.PayLineAskJournal, account.Configuration, + account.ConfigurationPaymentSequence, account.ConfigurationPaymentGroupSequence, party.Party, party.PartyPaymentDirectDebit, diff --git a/modules/account_payment/account.py b/modules/account_payment/account.py index 70280398f3..e80bf8c5e0 100644 --- a/modules/account_payment/account.py +++ b/modules/account_payment/account.py @@ -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' diff --git a/modules/account_payment/payment.py b/modules/account_payment/payment.py index 34830934af..fe814c7359 100644 --- a/modules/account_payment/payment.py +++ b/modules/account_payment/payment.py @@ -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: diff --git a/modules/account_payment/payment.xml b/modules/account_payment/payment.xml index 1376a40ecc..643c4a8cac 100644 --- a/modules/account_payment/payment.xml +++ b/modules/account_payment/payment.xml @@ -544,6 +544,23 @@ this repository contains the full copyright notices and license terms. --> Fail + + Account Payment Group + + + + + + + + + + + + Default Account Payment + + + Process Payments account.payment.process diff --git a/modules/account_payment/tests/scenario_account_payment.rst b/modules/account_payment/tests/scenario_account_payment.rst index d78d5a671f..8afc21cfdd 100644 --- a/modules/account_payment/tests/scenario_account_payment.rst +++ b/modules/account_payment/tests/scenario_account_payment.rst @@ -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 diff --git a/modules/account_payment/view/configuration_form.xml b/modules/account_payment/view/configuration_form.xml index 69d861f06c..28321cf9af 100644 --- a/modules/account_payment/view/configuration_form.xml +++ b/modules/account_payment/view/configuration_form.xml @@ -4,7 +4,9 @@ this repository contains the full copyright notices and license terms. --> - diff --git a/modules/account_payment/view/payment_form.xml b/modules/account_payment/view/payment_form.xml index 158ca2a648..466c50f50c 100644 --- a/modules/account_payment/view/payment_form.xml +++ b/modules/account_payment/view/payment_form.xml @@ -1,7 +1,12 @@ -
+ +