2014-12-02 12:54:50 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2021-12-11 17:58:41 +01:00
|
|
|
from trytond.model import DeactivableMixin, ModelSQL, ModelView, Unique, fields
|
2011-07-03 13:18:45 +02:00
|
|
|
from trytond.pool import Pool
|
2017-09-27 09:01:28 +02:00
|
|
|
from trytond.pyson import Eval
|
2021-12-11 17:58:41 +01:00
|
|
|
from trytond.transaction import Transaction
|
2008-06-10 22:01:27 +02:00
|
|
|
|
2008-06-17 12:09:01 +02:00
|
|
|
|
2021-06-29 00:32:12 +02:00
|
|
|
class Journal(DeactivableMixin, ModelSQL, ModelView):
|
2008-06-10 22:01:27 +02:00
|
|
|
'Statement Journal'
|
2012-09-24 22:17:36 +02:00
|
|
|
__name__ = 'account.statement.journal'
|
2008-06-17 12:09:01 +02:00
|
|
|
name = fields.Char('Name', required=True)
|
2021-03-05 15:49:19 +01:00
|
|
|
journal = fields.Many2One(
|
|
|
|
|
'account.journal', 'Journal', required=True,
|
|
|
|
|
domain=[('type', '=', 'statement')],
|
|
|
|
|
context={
|
|
|
|
|
'company': Eval('company', -1),
|
|
|
|
|
},
|
2022-04-08 19:07:12 +02:00
|
|
|
depends={'company'})
|
2008-06-10 22:01:27 +02:00
|
|
|
currency = fields.Many2One('currency.currency', 'Currency', required=True)
|
2022-10-11 00:44:49 +02:00
|
|
|
company = fields.Many2One('company.company', "Company", required=True)
|
2017-09-27 09:01:28 +02:00
|
|
|
company_party = fields.Function(
|
2021-03-05 15:49:19 +01:00
|
|
|
fields.Many2One(
|
|
|
|
|
'party.party', "Company Party",
|
|
|
|
|
context={
|
|
|
|
|
'company': Eval('company', -1),
|
|
|
|
|
},
|
2022-04-08 19:07:12 +02:00
|
|
|
depends={'company'}),
|
2017-09-27 09:01:28 +02:00
|
|
|
'on_change_with_company_party')
|
2014-07-20 13:45:45 +02:00
|
|
|
validation = fields.Selection([
|
|
|
|
|
('balance', 'Balance'),
|
|
|
|
|
('amount', 'Amount'),
|
|
|
|
|
('number_of_lines', 'Number of Lines'),
|
|
|
|
|
], 'Validation Type', required=True)
|
2017-09-27 09:01:28 +02:00
|
|
|
bank_account = fields.Many2One(
|
|
|
|
|
'bank.account', "Bank Account",
|
|
|
|
|
domain=[
|
|
|
|
|
('owners.id', '=', Eval('company_party', -1)),
|
|
|
|
|
('currency', '=', Eval('currency', -1)),
|
2022-04-08 19:07:12 +02:00
|
|
|
])
|
2018-09-01 11:19:35 +02:00
|
|
|
account = fields.Many2One('account.account', "Account", required=True,
|
|
|
|
|
domain=[
|
2019-03-24 18:00:01 +01:00
|
|
|
('type', '!=', None),
|
|
|
|
|
('closed', '!=', True),
|
2018-09-01 11:19:35 +02:00
|
|
|
('company', '=', Eval('company')),
|
2021-04-05 17:48:14 +02:00
|
|
|
('party_required', '=', False),
|
2022-04-08 19:07:12 +02:00
|
|
|
])
|
2017-09-27 09:01:28 +02:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super(Journal, cls).__setup__()
|
2019-01-30 11:58:45 +01:00
|
|
|
cls._order.insert(0, ('name', 'ASC'))
|
2017-09-27 09:01:28 +02:00
|
|
|
t = cls.__table__()
|
|
|
|
|
cls._sql_constraints = [
|
|
|
|
|
('bank_account_unique',
|
|
|
|
|
Unique(t, t.bank_account, t.company),
|
2018-12-29 14:20:29 +01:00
|
|
|
'account_statement.msg_journal_bank_account_unique'),
|
2017-09-27 09:01:28 +02:00
|
|
|
]
|
2008-06-10 22:01:27 +02:00
|
|
|
|
2012-09-24 22:17:36 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def default_currency():
|
2010-08-16 19:23:32 +02:00
|
|
|
if Transaction().context.get('company'):
|
2012-09-24 22:17:36 +02:00
|
|
|
Company = Pool().get('company.company')
|
|
|
|
|
company = Company(Transaction().context['company'])
|
2009-02-17 11:43:42 +01:00
|
|
|
return company.currency.id
|
2008-06-10 22:01:27 +02:00
|
|
|
|
2012-09-24 22:17:36 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def default_company():
|
2012-03-27 10:43:12 +02:00
|
|
|
return Transaction().context.get('company')
|
2014-07-20 13:45:45 +02:00
|
|
|
|
2017-09-27 09:01:28 +02:00
|
|
|
@fields.depends('company')
|
|
|
|
|
def on_change_with_company_party(self, name=None):
|
2023-03-26 09:49:00 +02:00
|
|
|
return self.company.party if self.company else None
|
2017-09-27 09:01:28 +02:00
|
|
|
|
2014-07-20 13:45:45 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def default_validation():
|
|
|
|
|
return 'balance'
|
2017-09-27 09:01:28 +02:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def get_by_bank_account(cls, company, number):
|
|
|
|
|
journals = cls.search([
|
|
|
|
|
('company', '=', company),
|
|
|
|
|
['OR',
|
|
|
|
|
('bank_account.numbers.number', '=', number),
|
|
|
|
|
('bank_account.numbers.number_compact', '=', number),
|
|
|
|
|
],
|
|
|
|
|
])
|
|
|
|
|
if journals:
|
|
|
|
|
journal, = journals
|
|
|
|
|
return journal
|