Refactor payment wizard so statement lines can be updated through inheritance.

This commit is contained in:
Albert Cervera i Areny 2019-12-16 00:09:10 +01:00
parent bddae61ca6
commit be34acc103
1 changed files with 13 additions and 8 deletions

21
sale.py
View File

@ -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'