From b16cec65d225cfde7d1e00f11c72266682ccd3c6 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 11 May 2010 15:10:59 +0530 Subject: [PATCH] [ADD,IMP]:account chart for configurable chart and improvements bzr revid: nch@tinyerp.com-20100511094059-oiz2eyhw54su4lus --- addons/account/account_installer.xml | 8 +- addons/account/configurable_account_chart.xml | 516 ++++++++++++++++++ addons/account/installer.py | 309 +++++++++-- addons/base_setup/__init__.py | 17 +- addons/base_setup/base_setup_data.xml | 10 +- addons/base_setup/base_setup_installer.xml | 4 +- addons/base_setup/gtk_contact_form.py | 10 +- addons/hr/hr_installer.xml | 1 - addons/knowledge/knowledge_installer.xml | 5 +- addons/mrp/mrp_installer.xml | 1 - .../profile_accounting/profile_accounting.xml | 3 + addons/profile_tools/misc_tools_installer.xml | 1 - addons/project/project_installer.xml | 1 - addons/purchase/wizard/purchase_installer.xml | 1 - .../report_designer_installer.xml | 1 - addons/sale/sale_view.xml | 1 - addons/thunderbird/thunderbird_installer.xml | 11 +- 17 files changed, 830 insertions(+), 70 deletions(-) create mode 100644 addons/account/configurable_account_chart.xml diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index 59c1240843b..f67946ff7a2 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -26,19 +26,15 @@ 23 - - - 190 - - + - +
diff --git a/addons/account/configurable_account_chart.xml b/addons/account/configurable_account_chart.xml new file mode 100644 index 00000000000..a6b271bedcb --- /dev/null +++ b/addons/account/configurable_account_chart.xml @@ -0,0 +1,516 @@ + + + + + + + Receivable + receivable + unreconciled + + + + Payable + payable + unreconciled + + + + View + view + none + + + + Income + income + none + + + + Expense + expense + none + + + + Tax + tax + unreconciled + + + + Cash + cash + balance + + + + Asset + asset + balance + + + + Equity + equity + balance + + + + Bank + bank + balance + + + Check + check + balance + + + + + + + 0 + Configurable Account Chart + + view + + + + + + + 1 + Balance Sheet + + view + + + + + 10 + Fixed Assets + + view + + + + + 100 + Fixed Asset Account + + other + + + + + 11 + Net Current Assets + + view + + + + + 110 + Current Assets + + view + + + + + 1101 + Purchased Stocks + + other + + + + + 1102 + Debtors + + receivable + + + + + + + + 1103 + Output VAT + + other + + + + + 1104 + Bank Current Account + + other + + + + + 1105 + Cash + + other + + + + + 111 + Current Liabilities + + view + + + + + 1111 + Creditors + + payable + + + + + + + + 1112 + Input VAT + + other + + + + + + + 2 + Profit and Loss + + view + + + + + 20 + Revenue + + view + + + + + 200 + Product Sales + + other + + + + + + + 21 + Cost of Sales + + view + + + + + 210 + Cost of Goods Sold + + other + + + + + 22 + Overheads + + view + + + + + 220 + Expenses + + other + + + + + + + + + + + + + + Plan Fees + + + + VAT Balance to Pay + + + + + Input VAT + + + + + + Input VAT Rate S (15%) + + + + + Input VAT Rate R (5%) + + + + + + + Output VAT + + + + + Output VAT Rate S (15%) + + + + + Output VAT Rate R (5%) + + + + + + + + + Tax Bases + + + + + Taxable Purchases Base + + + + + Taxable Purchases Rated S (15%) + + + + + Taxable Purchases Rated R (5%) + + + + + Taxable Purchases Rated Z (0%) + + + + + Taxable Purchases Type X (Exempt) + + + + + Taxable Purchases Type O (Out of scope) + + + + + + + Base of Taxable Sales + + + + + Taxable Sales Rated S (15%) + + + + + Taxable Sales Rated R (5%) + + + + + Taxable Sales Rated Z (0%) + + + + + Taxable Sales Type X (Exempt) + + + + + Taxable Sales Type O (Out of scope) + + + + + Configurable Account Chart Template + + + + + + + + + + + + + + + IVAT S + + percent + + + + + + + purchase + + + + + IVAT R + + percent + + + + + + + purchase + + + + + IVAT Z + + percent + + + purchase + + + + + IVAT X + + percent + + + purchase + + + + + IVAT O + + percent + + + purchase + + + + + + + OVAT S + + percent + + + + + + + sale + + + + + OVAT R + + percent + + + + + + + sale + + + + + OVAT Z + + percent + + + sale + + + + + OVAT X + + percent + + + sale + + + + + OVAT O + + percent + + + sale + + + diff --git a/addons/account/installer.py b/addons/account/installer.py index 760518f9006..fd0d3836581 100644 --- a/addons/account/installer.py +++ b/addons/account/installer.py @@ -21,10 +21,12 @@ import time import datetime from dateutil.relativedelta import relativedelta - +from tools.translate import _ from operator import itemgetter from osv import fields, osv import netsvc +import tools +from os.path import join as opj class account_installer(osv.osv_memory): _name = 'account.installer' @@ -37,19 +39,9 @@ class account_installer(osv.osv_memory): sorted(((m.name, m.shortdesc) for m in modules.browse(cr, uid, ids)), key=itemgetter(1))) + charts.insert(0,('configurable','Configurable Chart of Account')) return charts -# def default_get(self, cr, uid, fields_list=None, context=None): -# ''' set default accounts''' -# defaults = super(account_installer, self)\ -# .default_get(cr, uid, fields_list=fields_list, context=context) -# account = self.pool.get('account.bank.accounts.wizard') -# ids = [] -# for acc in ('Current','Deposit'): -# ids.append(account.create(cr, uid, {'acc_name':acc,'account_type':'cash','bank_account_id':self})) -# defaults.update({'bank_accounts_id':[(6,0,ids)]}) -# return defaults - _columns = { # Accounting 'charts':fields.selection(_get_charts, 'Chart of Accounts', @@ -84,7 +76,7 @@ class account_installer(osv.osv_memory): 'period':lambda *a:'month', 'sale_tax':lambda *a:0.0, 'purchase_tax':lambda *a:0.0, - 'charts':'l10n_chart_configurable', + 'charts':'configurable', } def on_change_start_date(self, cr, uid, id, start_date): @@ -94,37 +86,280 @@ class account_installer(osv.osv_memory): return {'value':{'date_stop':end_date.strftime('%Y-%m-%d')}} return {} + def generate_configurable_chart(self, cr, uid, ids, context=None): + mod_obj = self.pool.get('ir.model.data') + result = mod_obj._get_id(cr, uid, 'account', 'configurable_chart_template') + id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id'] + obj_multi = self.pool.get('account.chart.template').browse(cr,uid, id) + + obj_acc = self.pool.get('account.account') + obj_acc_tax = self.pool.get('account.tax') + obj_journal = self.pool.get('account.journal') + obj_sequence = self.pool.get('ir.sequence') + obj_acc_template = self.pool.get('account.account.template') + obj_fiscal_position_template = self.pool.get('account.fiscal.position.template') + obj_fiscal_position = self.pool.get('account.fiscal.position') + company_id = self.pool.get('res.users').browse(cr,uid,[uid],context)[0].company_id + seq_journal = True + + # Creating Account + obj_acc_root = obj_multi.account_root_id + tax_code_root_id = obj_multi.tax_code_root_id.id + + #new code + acc_template_ref = {} + tax_template_ref = {} + tax_code_template_ref = {} + todo_dict = {} + + #create all the tax code + children_tax_code_template = self.pool.get('account.tax.code.template').search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id') + children_tax_code_template.sort() + for tax_code_template in self.pool.get('account.tax.code.template').browse(cr, uid, children_tax_code_template): + vals={ + 'name': (tax_code_root_id == tax_code_template.id) and company_id.name or tax_code_template.name, + 'code': tax_code_template.code, + 'info': tax_code_template.info, + 'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False, + 'company_id': company_id.id, + 'sign': tax_code_template.sign, + } + new_tax_code = self.pool.get('account.tax.code').create(cr,uid,vals) + #recording the new tax code to do the mapping + tax_code_template_ref[tax_code_template.id] = new_tax_code + + #create all the tax + for tax in obj_multi.tax_template_ids: + #create it + vals_tax = { + 'name':tax.name, + 'sequence': tax.sequence, + 'amount':tax.amount, + 'type':tax.type, + 'applicable_type': tax.applicable_type, + 'domain':tax.domain, + 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, + 'child_depend': tax.child_depend, + 'python_compute': tax.python_compute, + 'python_compute_inv': tax.python_compute_inv, + 'python_applicable': tax.python_applicable, + 'tax_group':tax.tax_group, + 'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False, + 'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False, + 'base_sign': tax.base_sign, + 'tax_sign': tax.tax_sign, + 'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False, + 'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False, + 'ref_base_sign': tax.ref_base_sign, + 'ref_tax_sign': tax.ref_tax_sign, + 'include_base_amount': tax.include_base_amount, + 'description':tax.description, + 'company_id': company_id.id, + 'type_tax_use': tax.type_tax_use + } + new_tax = obj_acc_tax.create(cr,uid,vals_tax) + #as the accounts have not been created yet, we have to wait before filling these fields + todo_dict[new_tax] = { + 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False, + 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False, + } + tax_template_ref[tax.id] = new_tax + + #deactivate the parent_store functionnality on account_account for rapidity purpose + self.pool._init = True + + children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id]),('nocreate','!=',True)]) + children_acc_template.sort() + for account_template in obj_acc_template.browse(cr, uid, children_acc_template): + tax_ids = [] + for tax in account_template.tax_ids: + tax_ids.append(tax_template_ref[tax.id]) + #create the account_account + + dig = 6 + code_main = account_template.code and len(account_template.code) or 0 + code_acc = account_template.code or '' + if code_main>0 and code_main<=dig and account_template.type != 'view': + code_acc=str(code_acc) + (str('0'*(dig-code_main))) + vals={ + 'name': (obj_acc_root.id == account_template.id) and company_id.name or account_template.name, + #'sign': account_template.sign, + 'currency_id': account_template.currency_id and account_template.currency_id.id or False, + 'code': code_acc, + 'type': account_template.type, + 'user_type': account_template.user_type and account_template.user_type.id or False, + 'reconcile': account_template.reconcile, + 'shortcut': account_template.shortcut, + 'note': account_template.note, + 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False, + 'tax_ids': [(6,0,tax_ids)], + 'company_id': company_id.id, + } + new_account = obj_acc.create(cr,uid,vals) + acc_template_ref[account_template.id] = new_account + if account_template.name == 'Bank Current Account': + cash_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_cash') + cash_type_id = mod_obj.read(cr, uid, [cash_result], ['res_id'])[0]['res_id'] + + bank_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_bnk') + bank_type_id = mod_obj.read(cr, uid, [bank_result], ['res_id'])[0]['res_id'] + + check_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_chk') + check_type_id = mod_obj.read(cr, uid, [check_result], ['res_id'])[0]['res_id'] + + record = self.browse(cr, uid, ids, context=context)[0] + code_cnt = 1 + for val in record.bank_accounts_id: + if val.account_type == 'cash':type = cash_type_id + elif val.account_type == 'bank':type = bank_type_id + else:type = check_type_id + vals = {'name': val.acc_name or '', + 'currency_id': val.currency_id.id or False, + 'code': str(110400 + code_cnt), + 'type': 'other', + 'user_type': type, + 'parent_id':new_account, + 'company_id': company_id.id } + obj_acc.create(cr, uid, vals) + code_cnt += 1 + + #reactivate the parent_store functionnality on account_account + self.pool._init = False + self.pool.get('account.account')._parent_store_compute(cr) + + for key,value in todo_dict.items(): + if value['account_collected_id'] or value['account_paid_id']: + obj_acc_tax.write(cr, uid, [key], { + 'account_collected_id': acc_template_ref[value['account_collected_id']], + 'account_paid_id': acc_template_ref[value['account_paid_id']], + }) + + # Creating Journals + vals_journal={} + view_id = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Journal View')])[0] + seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0] + + if seq_journal: + seq_id_sale = obj_sequence.search(cr,uid,[('name','=','Sale Journal')])[0] + seq_id_purchase = obj_sequence.search(cr,uid,[('name','=','Purchase Journal')])[0] + else: + seq_id_sale = seq_id + seq_id_purchase = seq_id + + vals_journal['view_id'] = view_id + + #Sales Journal + vals_journal['name'] = _('Sales Journal') + vals_journal['type'] = 'sale' + vals_journal['code'] = _('SAJ') + vals_journal['sequence_id'] = seq_id_sale + + if obj_multi.property_account_receivable: + vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id] + vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id] + + obj_journal.create(cr,uid,vals_journal) + + # Purchase Journal + vals_journal['name'] = _('Purchase Journal') + vals_journal['type'] = 'purchase' + vals_journal['code'] = _('EXJ') + vals_journal['sequence_id'] = seq_id_purchase + + if obj_multi.property_account_payable: + vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id] + vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id] + + obj_journal.create(cr,uid,vals_journal) + + # Bank Journals + view_id_cash = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Cash Journal View')])[0] + view_id_cur = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Multi-Currency Cash Journal View')])[0] + ref_acc_bank = obj_multi.bank_account_view_id + + + #create the properties + property_obj = self.pool.get('ir.property') + fields_obj = self.pool.get('ir.model.fields') + + todo_list = [ + ('property_account_receivable','res.partner','account.account'), + ('property_account_payable','res.partner','account.account'), + ('property_account_expense_categ','product.category','account.account'), + ('property_account_income_categ','product.category','account.account'), + ('property_account_expense','product.template','account.account'), + ('property_account_income','product.template','account.account') + ] + for record in todo_list: + r = [] + r = property_obj.search(cr, uid, [('name','=', record[0] ),('company_id','=',company_id.id)]) + account = getattr(obj_multi, record[0]) + field = fields_obj.search(cr, uid, [('name','=',record[0]),('model','=',record[1]),('relation','=',record[2])]) + vals = { + 'name': record[0], + 'company_id': company_id.id, + 'fields_id': field[0], + 'value': account and 'account.account,'+str(acc_template_ref[account.id]) or False, + } + if r: + #the property exist: modify it + property_obj.write(cr, uid, r, vals) + else: + #create the property + property_obj.create(cr, uid, vals) + + fp_ids = obj_fiscal_position_template.search(cr, uid,[('chart_template_id', '=', obj_multi.id)]) + + if fp_ids: + for position in obj_fiscal_position_template.browse(cr, uid, fp_ids): + + vals_fp = { + 'company_id' : company_id.id, + 'name' : position.name, + } + new_fp = obj_fiscal_position.create(cr, uid, vals_fp) + + obj_tax_fp = self.pool.get('account.fiscal.position.tax') + obj_ac_fp = self.pool.get('account.fiscal.position.account') + + for tax in position.tax_ids: + vals_tax = { + 'tax_src_id' : tax_template_ref[tax.tax_src_id.id], + 'tax_dest_id' : tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False, + 'position_id' : new_fp, + } + obj_tax_fp.create(cr, uid, vals_tax) + + for acc in position.account_ids: + vals_acc = { + 'account_src_id' : acc_template_ref[acc.account_src_id.id], + 'account_dest_id' : acc_template_ref[acc.account_dest_id.id], + 'position_id' : new_fp, + } + obj_ac_fp.create(cr, uid, vals_acc) + def execute(self, cr, uid, ids, context=None): super(account_installer, self).execute(cr, uid, ids, context=context) record = self.browse(cr, uid, ids, context=context)[0] for res in self.read(cr,uid,ids): - if record.charts == 'l10n_chart_configurable': - obj_acc = self.pool.get('account.account') + if record.charts == 'configurable': + fp = tools.file_open(opj('account','configurable_account_chart.xml')) + tools.convert_xml_import(cr, 'account', fp, {}, 'init',True, None) + fp.close() + self.generate_configurable_chart(cr, uid, ids, context=context) obj_tax = self.pool.get('account.tax') - user_type = self.pool.get('account.account.type') obj_product = self.pool.get('product.product') ir_values = self.pool.get('ir.values') - u_type_id = user_type.search(cr, uid,[('name','ilike','view')])[0] - company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id - vals = {'name': company.name or '', - 'currency_id': company.currency_id.id or False, - 'code': 0 or '', - 'type': 'view', - 'user_type': u_type_id, - 'company_id': company.id } - main_account = obj_acc.create(cr, uid, vals) - for val in record.bank_accounts_id: - vals = {'name': val.acc_name or '', - 'currency_id': val.currency_id.id or False, - 'code': val.acc_name or '', - 'type': 'view', - 'user_type': u_type_id, - 'parent_id':main_account, - 'company_id': company.id } - obj_acc.create(cr, uid, vals) - - sales_tax = obj_tax.create(cr, uid,{'name':'sale Tax','amount':res.get('sale_tax',0.0)}) - purchase_tax = obj_tax.create(cr, uid,{'name':'purchase Tax','amount':res.get('purchase_tax',0.0)}) + s_tax = (res.get('sale_tax',0.0))/100 + p_tax = (res.get('purchase_tax',0.0))/100 + sales_tax = obj_tax.create(cr, uid, + {'name':'(%s)'%(s_tax*100), + 'amount':s_tax + }) + purchase_tax = obj_tax.create(cr, uid, + {'name':'(%s)'%(p_tax*100), + 'amount':p_tax + }) product_ids = obj_product.search(cr,uid, []) for product in obj_product.browse(cr, uid, product_ids): obj_product.write(cr, uid, product.id, {'taxes_id':[(6,0,[sales_tax])],'supplier_taxes_id':[(6,0,[purchase_tax])]}) diff --git a/addons/base_setup/__init__.py b/addons/base_setup/__init__.py index cda3e40111b..3b78c6cb557 100644 --- a/addons/base_setup/__init__.py +++ b/addons/base_setup/__init__.py @@ -23,7 +23,10 @@ import installer import todo import gtk_contact_form import wizard - +import os +import base64 +import random +import tools from osv import fields, osv import netsvc from tools.translate import _ @@ -34,6 +37,12 @@ class base_setup_config_choice(osv.osv_memory): _name = 'base.setup.config' logger = netsvc.Logger() + def _get_image(self, cr, uid, context=None): + file_no = str(random.randint(1,3)) + path = os.path.join('base','res','config_pixmaps/%s.png'%file_no) + file_data = tools.file_open(path,'rb').read() + return base64.encodestring(file_data) + def get_users(self, cr, uid, context={}): user_obj = self.pool.get('res.users') user_ids = user_obj.search(cr, uid, []) @@ -42,11 +51,13 @@ class base_setup_config_choice(osv.osv_memory): return _('The following users have been installed on your database: \n')+ user_str _columns = { - 'installed_users':fields.text('Installed Users', readonly=True) + 'installed_users':fields.text('Installed Users', readonly=True), + 'config_logo' : fields.binary('Image', readonly=True), } _defaults = { - 'installed_users':get_users + 'installed_users':get_users, + 'config_logo' : _get_image } def set_default_menu(self, cr, uid, menu, context=None): diff --git a/addons/base_setup/base_setup_data.xml b/addons/base_setup/base_setup_data.xml index e06facce0e8..90d48de5eba 100644 --- a/addons/base_setup/base_setup_data.xml +++ b/addons/base_setup/base_setup_data.xml @@ -7,11 +7,11 @@ form - - - - - + + + + + - 9 From this screen, you can select various OpenERP applications which will help employees store information, distribute it and share it with one another. - + + @@ -31,6 +31,7 @@ + Configure diff --git a/addons/mrp/mrp_installer.xml b/addons/mrp/mrp_installer.xml index d40eb453570..fe4fb6b8348 100644 --- a/addons/mrp/mrp_installer.xml +++ b/addons/mrp/mrp_installer.xml @@ -19,7 +19,6 @@ After having installed the core manufacturing application, you can extend it with a few more depending on the needs of your organization - 8 diff --git a/addons/profile_accounting/profile_accounting.xml b/addons/profile_accounting/profile_accounting.xml index d54aaaf1e5b..f9b143e10f4 100644 --- a/addons/profile_accounting/profile_accounting.xml +++ b/addons/profile_accounting/profile_accounting.xml @@ -11,6 +11,9 @@ Install Extra Modules + + + Tools Modules Installation - 10 diff --git a/addons/project/project_installer.xml b/addons/project/project_installer.xml index cbdd18ae29f..a127333544f 100644 --- a/addons/project/project_installer.xml +++ b/addons/project/project_installer.xml @@ -16,7 +16,6 @@ >Project Management
- 10 Purchase Modules Installation - 6 diff --git a/addons/report_designer/report_designer_installer.xml b/addons/report_designer/report_designer_installer.xml index 89d655de0b2..bcd0250fb7e 100644 --- a/addons/report_designer/report_designer_installer.xml +++ b/addons/report_designer/report_designer_installer.xml @@ -11,7 +11,6 @@ Report Modules Installation - 7 diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 3db8c67281b..5bf5967d58b 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -508,7 +508,6 @@ Setup your sales workflow and default values. - 100 6 diff --git a/addons/thunderbird/thunderbird_installer.xml b/addons/thunderbird/thunderbird_installer.xml index 59e0cc4f604..356282d2de5 100644 --- a/addons/thunderbird/thunderbird_installer.xml +++ b/addons/thunderbird/thunderbird_installer.xml @@ -12,13 +12,17 @@ Thunderbird Module Installation - Configure Thunderbird Module + Thunderbird This module is required for the thuderbird plug-in to work properly.This allows you to select an object that you had like to add to your email and its attachments. You can select a partner, a task, a project, an analytical account, or any other object and attach selected mail as .eml file in attachment of selected record. - - + + + 15 + + + @@ -33,6 +37,7 @@ +