From be34acc1030582e40705113413c6591aa72e0f68 Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Mon, 16 Dec 2019 00:09:10 +0100 Subject: [PATCH] Refactor payment wizard so statement lines can be updated through inheritance. --- sale.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sale.py b/sale.py index b34bf76..c1962cf 100644 --- a/sale.py +++ b/sale.py @@ -2,10 +2,8 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from decimal import Decimal -from sql import Cast, Literal from sql.aggregate import Sum from sql.conditionals import Coalesce -from sql.functions import Substring, Position from trytond.model import ModelView, fields from trytond.pool import PoolMeta, Pool @@ -222,7 +220,7 @@ class WizardSalePayment(Wizard): 'party': sale.party.id, } - def transition_pay_(self): + def get_statement_line(self, sale): pool = Pool() Date = pool.get('ir.date') Sale = pool.get('sale.sale') @@ -238,8 +236,6 @@ class WizardSalePayment(Wizard): raise UserError(gettext('sale_payment.not_draft_statement', journal=form.journal.name)) - active_id = Transaction().context.get('active_id', False) - sale = Sale(active_id) if not sale.number: Sale.set_number([sale]) @@ -252,16 +248,25 @@ class WizardSalePayment(Wizard): party=sale.party.name)) if form.payment_amount: - payment = StatementLine( + return StatementLine( statement=statements[0].id, date=Date.today(), amount=form.payment_amount, party=sale.party.id, account=account, description=sale.number, - sale=active_id + sale=sale.id, ) - payment.save() + + def transition_pay_(self): + Sale = Pool().get('sale.sale') + + active_id = Transaction().context.get('active_id', False) + sale = Sale(active_id) + + line = self.get_statement_line(sale) + if line: + line.save() if sale.total_amount != sale.paid_amount: return 'start'