Add payment type in account move/line
Revert changeset-0fcc1e6 and changeset-63aeda8
This commit is contained in:
parent
bce3623d52
commit
8b6291fdab
|
@ -1,9 +1,6 @@
|
|||
Version 4.2.0 - 2016-11-28
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Remove code from payment_type
|
||||
* Add both payment_type kind
|
||||
* Allow payment creation when the invoices are posted
|
||||
* Remove payment_type from Account Move Line
|
||||
|
||||
Version 4.0.0 - 2016-05-03
|
||||
* Return account_kind if account is payable/receivable despite of the move line
|
||||
|
|
17
__init__.py
17
__init__.py
|
@ -2,15 +2,18 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
import payment_type
|
||||
import party
|
||||
import invoice
|
||||
from .move import *
|
||||
from .payment_type import *
|
||||
from .party import *
|
||||
from .invoice import *
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
payment_type.PaymentType,
|
||||
party.PartyAccountPaymentType,
|
||||
party.Party,
|
||||
invoice.Invoice,
|
||||
Move,
|
||||
Line,
|
||||
PaymentType,
|
||||
PartyAccountPaymentType,
|
||||
Party,
|
||||
Invoice,
|
||||
module='account_payment_type', type_='model')
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
# 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 terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Move', 'Line']
|
||||
|
||||
|
||||
class Move:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'account.move'
|
||||
|
||||
def cancel(self, default=None):
|
||||
with Transaction().set_context(cancel_move=True):
|
||||
return super(Move, self).cancel(default=default)
|
||||
|
||||
|
||||
class Line:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'account.move.line'
|
||||
|
||||
account_kind = fields.Function(fields.Selection([
|
||||
('', ''),
|
||||
('payable', 'Payable'),
|
||||
('receivable', 'Receivable')
|
||||
], 'Kind'),
|
||||
'on_change_with_account_kind', searcher='search_account_kind')
|
||||
payment_type = fields.Many2One('account.payment.type',
|
||||
'Payment Type', domain=[
|
||||
('kind', 'in', ['both', Eval('account_kind')]),
|
||||
], depends=['account_kind', 'reconciliation'],
|
||||
states={
|
||||
'readonly': Bool(Eval('reconciliation')),
|
||||
'invisible': ~Eval('account_kind', '').in_(
|
||||
['payable', 'receivable']),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Line, cls).__setup__()
|
||||
if hasattr(cls, '_check_modify_exclude'):
|
||||
cls._check_modify_exclude.add('payment_type')
|
||||
cls._error_messages.update({
|
||||
'invalid_account_payment_type': ('Can not set Payment Type in '
|
||||
'move line "%s" because account is not Payable nor '
|
||||
'Receivable.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def validate(cls, lines):
|
||||
super(Line, cls).validate(lines)
|
||||
for line in lines:
|
||||
line.check_account_payment_type()
|
||||
|
||||
@classmethod
|
||||
def copy(cls, lines, default=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
if (Transaction().context.get('cancel_move') and not 'payment_type' in
|
||||
default):
|
||||
default['payment_type'] = None
|
||||
return super(Line, cls).copy(lines, default)
|
||||
|
||||
def check_account_payment_type(self):
|
||||
if (self.payment_type
|
||||
and self.account.kind not in ('payable', 'receivable')):
|
||||
self.raise_user_error('invalid_account_payment_type',
|
||||
(self.rec_name,))
|
||||
|
||||
@fields.depends('account', 'credit', 'debit')
|
||||
def on_change_with_account_kind(self, name=None):
|
||||
if self.account and self.account.kind in ('payable', 'receivable'):
|
||||
if self.credit > 0 or self.debit < 0:
|
||||
return 'payable'
|
||||
elif self.debit > 0 or self.credit < 0:
|
||||
return 'receivable'
|
||||
return self.account.kind
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
def search_account_kind(cls, name, clause):
|
||||
return [('account.kind',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('account')
|
||||
def on_change_account(self):
|
||||
super(Line, self).on_change_account()
|
||||
if self.account and self.account.kind in ('payable', 'receivable'):
|
||||
self.account_kind = self.account.kind
|
|
@ -0,0 +1,19 @@
|
|||
<?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 terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<!-- account.move.line -->
|
||||
<record model="ir.ui.view" id="move_line_view_form">
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit" ref="account.move_line_view_form"/>
|
||||
<field name="name">move_line_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="move_line_view_form_move">
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit" ref="account.move_line_view_form_move"/>
|
||||
<field name="name">move_line_form_move</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
|
@ -38,10 +38,10 @@ Create chart of accounts::
|
|||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> cash = accounts['cash']
|
||||
>>> account_receivable = accounts['receivable']
|
||||
>>> account_revenue = accounts['revenue']
|
||||
>>> account_expense = accounts['expense']
|
||||
>>> account_cash = accounts['cash']
|
||||
|
||||
Create tax::
|
||||
|
||||
|
@ -61,8 +61,8 @@ Create product::
|
|||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('50')
|
||||
>>> template.cost_price = Decimal('25')
|
||||
>>> template.account_expense = expense
|
||||
>>> template.account_revenue = revenue
|
||||
>>> template.account_expense = account_expense
|
||||
>>> template.account_revenue = account_revenue
|
||||
>>> template.customer_taxes.append(tax)
|
||||
>>> template.save()
|
||||
>>> product.template = template
|
||||
|
@ -196,9 +196,9 @@ We can use both in negative and positive invoices::
|
|||
>>> invoice.untaxed_amount
|
||||
Decimal('50.00')
|
||||
>>> invoice.save()
|
||||
|
||||
>>> invoice.payment_type == both
|
||||
True
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_term = payment_term
|
||||
|
@ -210,3 +210,24 @@ We can use both in negative and positive invoices::
|
|||
>>> invoice.save()
|
||||
>>> invoice.payment_type == both
|
||||
True
|
||||
|
||||
Post an invoice with payment type::
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_term = payment_term
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('50.0')
|
||||
>>> invoice.payment_type = receivable
|
||||
>>> invoice.untaxed_amount
|
||||
Decimal('50.00')
|
||||
>>> invoice.save()
|
||||
>>> invoice.click('post')
|
||||
>>> import pdb; pdb.set_trace()
|
||||
>>> line1, _, _ = invoice.move.lines
|
||||
>>> line1.payment_type == receivable
|
||||
True
|
||||
>>> line1.account == account_receivable
|
||||
True
|
||||
|
|
|
@ -1,19 +1,85 @@
|
|||
# This file is part of the account_payment_type module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
import doctest
|
||||
import unittest
|
||||
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import doctest_teardown
|
||||
from trytond.tests.test_tryton import doctest_checker
|
||||
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
||||
from trytond.modules.account_invoice.tests import set_invoice_sequences
|
||||
|
||||
|
||||
class AccountPaymentTypeTestCase(ModuleTestCase):
|
||||
'Test Account Payment Type module'
|
||||
module = 'account_payment_type'
|
||||
|
||||
@with_transaction()
|
||||
def test_move_lines(self):
|
||||
'Test move lines'
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
FiscalYear = pool.get('account.fiscalyear')
|
||||
Journal = pool.get('account.journal')
|
||||
Move = pool.get('account.move')
|
||||
MoveLine = pool.get('account.move.line')
|
||||
PaymentType = pool.get('account.payment.type')
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
create_chart(company)
|
||||
fiscalyear = get_fiscalyear(company)
|
||||
set_invoice_sequences(fiscalyear)
|
||||
fiscalyear.save()
|
||||
FiscalYear.create_period([fiscalyear])
|
||||
period = fiscalyear.periods[0]
|
||||
|
||||
journal_revenue, = Journal.search([
|
||||
('code', '=', 'REV'),
|
||||
])
|
||||
revenue, = Account.search([
|
||||
('kind', '=', 'revenue'),
|
||||
])
|
||||
receivable, = Account.search([
|
||||
('kind', '=', 'receivable'),
|
||||
])
|
||||
payable, = Account.search([
|
||||
('kind', '=', 'payable'),
|
||||
])
|
||||
payment_payable, = PaymentType.create([{
|
||||
'name': 'Payment Payable',
|
||||
'kind': 'payable',
|
||||
'company': company.id,
|
||||
}])
|
||||
payment_receivable, = PaymentType.create([{
|
||||
'name': 'Payment Receivable',
|
||||
'kind': 'receivable',
|
||||
'company': company.id,
|
||||
}])
|
||||
move, = Move.create([{
|
||||
'period': period.id,
|
||||
'journal': journal_revenue.id,
|
||||
'date': period.start_date,
|
||||
}])
|
||||
MoveLine.create([{
|
||||
'move': move.id,
|
||||
'account': revenue.id,
|
||||
'debit': Decimal(30),
|
||||
}])
|
||||
self.assertRaises(Exception, MoveLine.create, [{
|
||||
'move': move.id,
|
||||
'account': revenue.id,
|
||||
'debit': Decimal(30),
|
||||
'payment_type': payment_receivable,
|
||||
}])
|
||||
# TODO Create move line payment + payment type payable
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
|
|
|
@ -4,6 +4,7 @@ depends:
|
|||
account_invoice
|
||||
account_payment
|
||||
xml:
|
||||
move.xml
|
||||
payment_type.xml
|
||||
party.xml
|
||||
invoice.xml
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page/field[@name="second_currency"]"
|
||||
position="after">
|
||||
<label name="payment_type"/>
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page/field[@name="second_currency"]"
|
||||
position="after">
|
||||
<label name="payment_type"/>
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue