other minimum changes
This commit is contained in:
parent
f9d5559749
commit
07c65f0484
12
__init__.py
12
__init__.py
|
@ -3,14 +3,18 @@
|
|||
|
||||
from trytond.pool import Pool
|
||||
from . import sale
|
||||
from . import statement
|
||||
__all__ = ['register']
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
sale.SalePaymentForm,
|
||||
module='sale_payment_form', type_='model')
|
||||
sale.SalePaymentForm,
|
||||
statement.Line,
|
||||
module='sale_payment_form', type_='model')
|
||||
Pool.register(
|
||||
module='sale_payment_form', type_='wizard')
|
||||
sale.WizardSalePayment,
|
||||
sale.WizardSaleReconcile,
|
||||
module='sale_payment_form', type_='wizard')
|
||||
Pool.register(
|
||||
module='sale_payment_form', type_='report')
|
||||
module='sale_payment_form', type_='report')
|
||||
|
|
104
sale.py
104
sale.py
|
@ -13,6 +13,7 @@ from trytond.wizard import Wizard, StateView, StateTransition, Button
|
|||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
|
||||
class SalePaymentForm(metaclass=PoolMeta):
|
||||
'Sale Payment Form'
|
||||
__name__ = 'sale.payment.form'
|
||||
|
@ -63,9 +64,16 @@ class SalePaymentForm(metaclass=PoolMeta):
|
|||
if self.payment_amount > amount:
|
||||
self.payment_amount = amount
|
||||
|
||||
|
||||
class WizardSalePayment(metaclass=PoolMeta):
|
||||
'Wizard Sale Payment'
|
||||
__name__ = 'sale.payment'
|
||||
start = StateView('sale.payment.form',
|
||||
'sale_payment.sale_payment_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Pay', 'pay_', 'tryton-ok', default=True),
|
||||
])
|
||||
pay_ = StateTransition()
|
||||
|
||||
def default_start(self, fields):
|
||||
pool = Pool()
|
||||
|
@ -80,10 +88,102 @@ class WizardSalePayment(metaclass=PoolMeta):
|
|||
'journal': sale_device.journal.id
|
||||
if sale_device.journal else None,
|
||||
'journals': [j.id for j in sale_device.journals],
|
||||
'paid_amount': sale.paid_amount,
|
||||
'payment_amount': sale.total_amount - sale.paid_amount,
|
||||
'payment_amount': sale.total_amount - sale.paid_amount
|
||||
if sale.paid_amount else sale.total_amount,
|
||||
'currency_digits': sale.currency_digits,
|
||||
'party': sale.party.id,
|
||||
}
|
||||
|
||||
def get_statement_line(self, sale):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
Sale = pool.get('sale.sale')
|
||||
Statement = pool.get('account.statement')
|
||||
StatementLine = pool.get('account.statement.line')
|
||||
|
||||
form = self.start
|
||||
statements = Statement.search([
|
||||
('journal', '=', form.journal),
|
||||
('state', '=', 'draft'),
|
||||
], order=[('date', 'DESC')])
|
||||
if not statements:
|
||||
raise UserError(gettext('sale_payment.not_draft_statement',
|
||||
journal=form.journal.name))
|
||||
|
||||
if not sale.number:
|
||||
Sale.set_number([sale])
|
||||
|
||||
with Transaction().set_context(date=Date.today()):
|
||||
account = sale.party.account_receivable_used
|
||||
|
||||
if not account:
|
||||
raise UserError(gettext(
|
||||
'sale_payment.party_without_account_receivable',
|
||||
party=sale.party.name))
|
||||
if form.payment_amount:
|
||||
return StatementLine(
|
||||
statement=statements[0],
|
||||
date=Date.today(),
|
||||
amount=form.payment_amount,
|
||||
party=sale.party,
|
||||
invoice=sale.invoices[0].id,
|
||||
account=account,
|
||||
description=sale.number,
|
||||
sale=sale,
|
||||
)
|
||||
|
||||
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'
|
||||
if sale.state != 'draft':
|
||||
return 'end'
|
||||
|
||||
sale.description = sale.reference
|
||||
sale.save()
|
||||
Sale.workflow_to_end([sale])
|
||||
|
||||
return 'end'
|
||||
|
||||
|
||||
class WizardSaleReconcile(Wizard):
|
||||
'Reconcile Sales'
|
||||
__name__ = 'sale.reconcile'
|
||||
start = StateTransition()
|
||||
reconcile = StateTransition()
|
||||
|
||||
def transition_start(self):
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
Line = pool.get('account.move.line')
|
||||
for sale in Sale.browse(Transaction().context['active_ids']):
|
||||
account = sale.party.account_receivable_used
|
||||
lines = []
|
||||
amount = Decimal('0.0')
|
||||
for invoice in sale.invoices:
|
||||
for line in invoice.lines_to_pay:
|
||||
if not line.reconciliation:
|
||||
lines.append(line)
|
||||
amount += line.debit - line.credit
|
||||
for payment in sale.payments:
|
||||
if not payment.move:
|
||||
continue
|
||||
for line in payment.move.lines:
|
||||
if (not line.reconciliation and
|
||||
line.account.id == account.id):
|
||||
lines.append(line)
|
||||
amount += line.debit - line.credit
|
||||
if lines and amount == Decimal('0.0'):
|
||||
Line.reconcile(lines)
|
||||
return 'end'
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# This file is part of the sale_payment module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from decimal import Decimal
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
__all__ = ['Line']
|
||||
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
__name__ = 'account.statement.line'
|
||||
sale = fields.Many2One('sale.sale', 'Sale', ondelete='RESTRICT')
|
||||
unblocked = fields.Boolean('unblocked', 'Unblocked', select=False)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
for line in lines:
|
||||
if line.unblocked == False:
|
||||
raise UserError(str(line.unblocked))
|
||||
super(Line, cls).delete(lines)
|
||||
|
||||
def create_move(self):
|
||||
'''
|
||||
Create move for the statement line and return move if created.
|
||||
Redefined method to allow amounts in statement lines greater than the
|
||||
invoice amount.
|
||||
'''
|
||||
pool = Pool()
|
||||
Move = pool.get('account.move')
|
||||
Period = pool.get('account.period')
|
||||
Invoice = pool.get('account.invoice')
|
||||
Currency = pool.get('currency.currency')
|
||||
MoveLine = pool.get('account.move.line')
|
||||
|
||||
if self.move:
|
||||
return
|
||||
|
||||
period_id = Period.find(self.statement.company.id, date=self.date)
|
||||
|
||||
move_lines = self._get_move_lines()
|
||||
move = Move(
|
||||
period=period_id,
|
||||
journal=self.statement.journal.journal,
|
||||
date=self.date,
|
||||
origin=self,
|
||||
lines=move_lines,
|
||||
)
|
||||
move.save()
|
||||
|
||||
self.write([self], {
|
||||
'move': move.id,
|
||||
})
|
||||
|
||||
if self.invoice:
|
||||
with Transaction().set_context(date=self.invoice.currency_date):
|
||||
amount = Currency.compute(self.statement.journal.currency,
|
||||
self.amount, self.statement.company.currency)
|
||||
|
||||
reconcile_lines = self.invoice.get_reconcile_lines_for_amount(
|
||||
abs(amount))
|
||||
|
||||
for move_line in move.lines:
|
||||
if move_line.account == self.invoice.account:
|
||||
Invoice.write([self.invoice], {
|
||||
'payment_lines': [('add', [move_line.id])],
|
||||
})
|
||||
break
|
||||
if reconcile_lines[1] == Decimal('0.0'):
|
||||
lines = reconcile_lines[0] + [move_line]
|
||||
MoveLine.reconcile(lines)
|
||||
return move
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of the sale_payment module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="statement_line_view_form">
|
||||
<field name="model">account.statement.line</field>
|
||||
<field name="inherit" ref="account_statement.statement_line_view_form"/>
|
||||
<field name="name">statement_line_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
|
@ -7,3 +7,4 @@ depends:
|
|||
sale_payment
|
||||
xml:
|
||||
sale.xml
|
||||
statement.xml
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of account_payment_type module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license types. -->
|
||||
<data>
|
||||
<xpath expr="//field[@name='date']" position="after">
|
||||
<label name="unblocked"/>
|
||||
<field name="unblocked"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue