@@ -774,6 +774,11 @@ class Invoice(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice'
|
||||
|
||||
payment_direct_debit = fields.Boolean("Direct Debit",
|
||||
domain=[
|
||||
If(Eval('type') != 'in',
|
||||
('payment_direct_debit', '=', False),
|
||||
()),
|
||||
],
|
||||
states={
|
||||
'invisible': Eval('type') != 'in',
|
||||
'readonly': Eval('state') != 'draft',
|
||||
@@ -784,11 +789,13 @@ class Invoice(metaclass=PoolMeta):
|
||||
def default_payment_direct_debit(cls):
|
||||
return False
|
||||
|
||||
@fields.depends('party')
|
||||
@fields.depends('party', 'type')
|
||||
def on_change_party(self):
|
||||
super().on_change_party()
|
||||
if self.party:
|
||||
if self.type == 'in' and self.party:
|
||||
self.payment_direct_debit = self.party.payment_direct_debit
|
||||
else:
|
||||
self.payment_direct_debit = False
|
||||
|
||||
def _get_move_line(self, date, amount):
|
||||
line = super()._get_move_line(date, amount)
|
||||
|
||||
@@ -129,27 +129,3 @@ Check amount to pay::
|
||||
>>> invoice.reload()
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('40.00')
|
||||
|
||||
Set party as direct debit::
|
||||
|
||||
>>> party.payment_direct_debit = True
|
||||
>>> party.save()
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice(type='out')
|
||||
>>> invoice.party = party
|
||||
>>> bool(invoice.payment_direct_debit)
|
||||
True
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.description = 'Description'
|
||||
>>> line.account = revenue
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('50')
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
>>> line_to_pay, = invoice.lines_to_pay
|
||||
>>> bool(line_to_pay.payment_direct_debit)
|
||||
True
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"payment_direct_debit": false}
|
||||
,{"payment_direct_debit": true}
|
||||
]
|
||||
@@ -0,0 +1,56 @@
|
||||
===========================================
|
||||
Account Payment Party Direct Debit Scenario
|
||||
===========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> payment_direct_debit = globals().get('payment_direct_debit', False)
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment', 'account_invoice'], create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> party = Party(name='Supplier')
|
||||
>>> party.payment_direct_debit = payment_direct_debit
|
||||
>>> party.save()
|
||||
|
||||
Create supplier invoice::
|
||||
|
||||
>>> invoice = Invoice(type='in')
|
||||
>>> invoice.party = party
|
||||
>>> invoice.invoice_date = today
|
||||
>>> assertEqual(invoice.payment_direct_debit, payment_direct_debit)
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.account = accounts['expense']
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('50.0000')
|
||||
>>> invoice.click('post')
|
||||
>>> line_to_pay, = invoice.lines_to_pay
|
||||
>>> assertEqual(line_to_pay.payment_direct_debit, payment_direct_debit)
|
||||
Reference in New Issue
Block a user