From 095e237fb86a45850e9a3715ea3a59cd4d1ee237 Mon Sep 17 00:00:00 2001 From: Nathanael Perat Date: Mon, 31 Oct 2011 14:55:49 +0100 Subject: [PATCH] fixed default account receivable/payable properties issue 1342 review 162006 --- __init__.py | 1 + __tryton__.py | 1 + configuration.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++ configuration.xml | 36 ++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 configuration.py create mode 100644 configuration.xml diff --git a/__init__.py b/__init__.py index 64eed1c814..52ca16f605 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,7 @@ from fiscalyear import * from account import * +from configuration import * from period import * from journal import * from move import * diff --git a/__tryton__.py b/__tryton__.py index 46f3ea3336..4494a4af84 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -133,6 +133,7 @@ Met bijbehorende rapporten: ], 'xml': [ 'account.xml', + 'configuration.xml', 'fiscalyear.xml', 'period.xml', 'journal.xml', diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000000..bfecc55fe2 --- /dev/null +++ b/configuration.py @@ -0,0 +1,78 @@ +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. +import re +from trytond.model import ModelView, ModelSQL, ModelSingleton, fields +from trytond.pool import Pool +from trytond.transaction import Transaction +from trytond.pyson import Eval, Bool + + +class Configuration(ModelSingleton, ModelSQL, ModelView): + 'Account Configuration' + _name = 'account.configuration' + _description = __doc__ + + default_account_receivable = fields.Function(fields.Many2One( + 'account.account', 'Default Account Receivable', + domain=[ + ('kind', '=', 'receivable'), + ('company', '=', Eval('context', {}).get('company')), + ]), + 'get_account', setter='set_account') + default_account_payable = fields.Function(fields.Many2One( + 'account.account', 'Default Account Payable', + domain=[ + ('kind', '=', 'payable'), + ('company', '=', Eval('context', {}).get('company')), + ]), + 'get_account', setter='set_account') + + def get_account(self, ids, name): + property_obj = Pool().get('ir.property') + model_field_obj = Pool().get('ir.model.field') + company = Transaction().context.get('company') + res = {} + if not ids: + return res + accounts = self.browse(ids) + account_field_id, = model_field_obj.search([ + ('model.model', '=', 'party.party'), + ('name', '=', name[8:]), + ], limit=1) + for account in accounts: + property_ids = property_obj.search([ + ('field', '=', account_field_id), + ('res', '=', False), + ('company', '=', company), + ], limit=1) + if property_ids: + prop = property_obj.browse(property_ids[0]) + res[account.id] = int(prop.value.split(',')[1]) + else: + res[account.id] = False + return res + + def set_account(self, ids, name, value): + property_obj = Pool().get('ir.property') + model_field_obj = Pool().get('ir.model.field') + company = Transaction().context.get('company') + account_field_id, = model_field_obj.search([ + ('model.model', '=', 'party.party'), + ('name', '=', name[8:]), + ], limit=1) + property_ids = property_obj.search([ + ('field', '=', account_field_id), + ('res', '=', False), + ('company', '=', company), + ]) + with Transaction().set_user(0): + property_obj.delete(property_ids) + if value: + property_obj.create({ + 'name': name[8:], + 'field': account_field_id, + 'value': 'account.account,%s' % value, + 'company': company, + }) + +Configuration() diff --git a/configuration.xml b/configuration.xml new file mode 100644 index 0000000000..84c206b3ec --- /dev/null +++ b/configuration.xml @@ -0,0 +1,36 @@ + + + + + + account.configuration + form + + + + + Account Configuration + account.configuration + + + + + + + + +