Drop required on party receivable and payable accounts
Use the default account defined on configuration when the value is not set issue6561 review40441002
This commit is contained in:
1 parent
67cda0a166
commit
aa71a1e6f5
3 files changed
+68
-21
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Drop required on party payable and receivable accounts
|
||||
* Make tax description translatable
|
||||
* Add searcher on General Ledger
|
||||
* Add from and to date to General Ledger and Income Statement
|
||||
|
||||
@@ -8,7 +8,7 @@ from sql.conditionals import Coalesce
|
||||
|
||||
from trytond import backend
|
||||
from trytond.model import ModelSQL, fields
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.tools import reduce_ids, grouped_slice
|
||||
@@ -33,7 +33,6 @@ class Party(CompanyMultiValueMixin):
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
states={
|
||||
'required': Bool(Eval('context', {}).get('company')),
|
||||
'invisible': ~Eval('context', {}).get('company'),
|
||||
}))
|
||||
account_receivable = fields.MultiValue(fields.Many2One(
|
||||
@@ -43,7 +42,6 @@ class Party(CompanyMultiValueMixin):
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
states={
|
||||
'required': Bool(Eval('context', {}).get('company')),
|
||||
'invisible': ~Eval('context', {}).get('company'),
|
||||
}))
|
||||
customer_tax_rule = fields.MultiValue(fields.Many2One(
|
||||
@@ -83,6 +81,16 @@ class Party(CompanyMultiValueMixin):
|
||||
depends=['currency_digits']),
|
||||
'get_receivable_payable', searcher='search_receivable_payable')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Party, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'missing_receivable_account': (
|
||||
'There is no receivable account on party "%(name)s".'),
|
||||
'missing_payable_account': (
|
||||
'There is no payable account on party "%(name)s".'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def multivalue_model(cls, field):
|
||||
pool = Pool()
|
||||
@@ -90,24 +98,6 @@ class Party(CompanyMultiValueMixin):
|
||||
return pool.get('party.party.account')
|
||||
return super(Party, cls).multivalue_model(field)
|
||||
|
||||
@classmethod
|
||||
def default_account_payable(cls, **pattern):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
config = Configuration(1)
|
||||
account = config.get_multivalue(
|
||||
'default_account_payable', **pattern)
|
||||
return account.id if account else None
|
||||
|
||||
@classmethod
|
||||
def default_account_receivable(cls, **pattern):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
config = Configuration(1)
|
||||
account = config.get_multivalue(
|
||||
'default_account_receivable', **pattern)
|
||||
return account.id if account else None
|
||||
|
||||
@classmethod
|
||||
def get_currency_digits(cls, parties, name):
|
||||
pool = Pool()
|
||||
@@ -234,6 +224,34 @@ class Party(CompanyMultiValueMixin):
|
||||
having=Operator(amount, value))
|
||||
return [('id', 'in', query)]
|
||||
|
||||
@property
|
||||
def account_payable_used(self):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
account = self.account_payable
|
||||
if not account:
|
||||
config = Configuration(1)
|
||||
account = config.get_multivalue('default_account_payable')
|
||||
if not account:
|
||||
self.raise_user_error('missing_payable_account', {
|
||||
'name': self.rec_name,
|
||||
})
|
||||
return account
|
||||
|
||||
@property
|
||||
def account_receivable_used(self):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
account = self.account_receivable
|
||||
if not account:
|
||||
config = Configuration(1)
|
||||
account = config.get_multivalue('default_account_receivable')
|
||||
if not account:
|
||||
self.raise_user_error('missing_receivable_account', {
|
||||
'name': self.rec_name,
|
||||
})
|
||||
return account
|
||||
|
||||
|
||||
class PartyAccount(ModelSQL, CompanyValueMixin):
|
||||
"Party Account"
|
||||
|
||||
@@ -993,6 +993,34 @@ class AccountTestCase(ModuleTestCase):
|
||||
self.assertSequenceEqual(
|
||||
Tax.sort_taxes([tax3, tax2, tax1]), [tax1, tax2, tax3])
|
||||
|
||||
@with_transaction()
|
||||
def test_configuration_accounts_on_party(self):
|
||||
'Test configuration accounts are used as fallback on party'
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Account = pool.get('account.account')
|
||||
|
||||
party = Party(name='Party')
|
||||
party.save()
|
||||
|
||||
self.assertIsNone(party.account_payable)
|
||||
self.assertIsNone(party.account_receivable)
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
create_chart(company)
|
||||
receivable, = Account.search([
|
||||
('kind', '=', 'receivable'),
|
||||
])
|
||||
payable, = Account.search([
|
||||
('kind', '=', 'payable'),
|
||||
])
|
||||
|
||||
party = Party(party.id)
|
||||
|
||||
self.assertEqual(party.account_payable_used, payable)
|
||||
self.assertEqual(party.account_receivable_used, receivable)
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
|
||||
Reference in new issue
Block a user