75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
# 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
|