[IMP]: account: l10n fullness and inheritancy: Move the tax_generate function to account.tax.template
bzr revid: ron@tinyerp.com-20110808094118-4uhlhm6s63n17qj9
This commit is contained in:
parent
e92fc06a2c
commit
fbd83912b0
|
@ -2574,6 +2574,64 @@ class account_tax_template(osv.osv):
|
|||
}
|
||||
_order = 'sequence'
|
||||
|
||||
def generate_tax(self, cr, uid, ids, tax_templates_load, tax_code_template_ref, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
todo_dict = {}
|
||||
tax_template_ref = {}
|
||||
tax_template_to_tax = {}
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
|
||||
if not context.get('false_tax_template'):
|
||||
obj_multi = self.browse(cr, uid, ids[0])
|
||||
company_id = obj_multi.company_id.id
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
for tax in tax_templates_load:
|
||||
# #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,
|
||||
'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,
|
||||
'type_tax_use': tax.type_tax_use,
|
||||
'price_include': tax.price_include
|
||||
}
|
||||
new_tax = self.pool.get('account.tax').create(cr, uid, vals_tax)
|
||||
tax_template_to_tax[tax.id] = new_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
|
||||
if not context.get('false_tax_template'):
|
||||
if obj_multi.sale_tax and tax_template_to_tax:
|
||||
ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id,
|
||||
models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]])
|
||||
if obj_multi.purchase_tax and tax_template_to_tax:
|
||||
ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id,
|
||||
models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]])
|
||||
res.update({'taxes_id': tax_template_to_tax, 'account_dict': todo_dict, 'tax_template_ref': tax_template_ref})
|
||||
return res
|
||||
|
||||
account_tax_template()
|
||||
|
||||
# Fiscal Position Templates
|
||||
|
@ -2719,63 +2777,6 @@ class wizard_multi_charts_accounts(osv.osv_memory):
|
|||
res['fields'][field]['selection'] = template_select
|
||||
return res
|
||||
|
||||
def generate_tax(self, cr, uid, ids, tax_templates_load, tax_code_template_ref, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
todo_dict = {}
|
||||
tax_template_ref = {}
|
||||
tax_template_to_tax = {}
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
|
||||
if not context.get('false_tax_template'):
|
||||
obj_multi = self.browse(cr, uid, ids[0])
|
||||
company_id = obj_multi.company_id.id
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
for tax in tax_templates_load:
|
||||
# #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,
|
||||
'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,
|
||||
'type_tax_use': tax.type_tax_use,
|
||||
'price_include': tax.price_include
|
||||
}
|
||||
new_tax = self.pool.get('account.tax').create(cr, uid, vals_tax)
|
||||
tax_template_to_tax[tax.id] = new_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
|
||||
if not context.get('false_tax_template'):
|
||||
if obj_multi.sale_tax and tax_template_to_tax:
|
||||
ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id,
|
||||
models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]])
|
||||
if obj_multi.purchase_tax and tax_template_to_tax:
|
||||
ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id,
|
||||
models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]])
|
||||
res.update({'taxes_id': tax_template_to_tax, 'account_dict': todo_dict, 'tax_template_ref': tax_template_ref})
|
||||
return res
|
||||
|
||||
def execute(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
|
@ -2845,7 +2846,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
|
|||
tax_template_to_tax = {}
|
||||
context.update({'false_tax_template': False})
|
||||
tax_templates_load = [x for x in obj_multi.chart_template_id.tax_template_ids if x.installable]
|
||||
taxes_ids = self.generate_tax(cr, uid, ids, tax_templates_load, tax_code_template_ref, context=context)
|
||||
taxes_ids = obj_tax_temp.generate_tax(cr, uid, ids, tax_templates_load, tax_code_template_ref, context=context)
|
||||
#deactivate the parent_store functionnality on account_account for rapidity purpose
|
||||
ctx = context and context.copy() or {}
|
||||
ctx['defer_parent_store_computation'] = True
|
||||
|
|
|
@ -38,9 +38,10 @@ class account_tax_generate(osv.osv_memory):
|
|||
|
||||
def tax_generate(self, cr, uid, ids, context=None):
|
||||
context.update({'false_tax_template': True})
|
||||
obj_tax_temp = self.pool.get('account.tax.template')
|
||||
tax_templates_load = [x for x in self.browse(cr, uid, ids, context=context)[0].template_ids]
|
||||
taxes_ids = self.pool.get('wizard.multi.charts.accounts').generate_tax(cr, uid, ids, tax_templates_load, {}, context=context)
|
||||
self.pool.get('account.tax.template').write(cr, uid , taxes_ids['taxes_id'].keys(), {'installable': True})
|
||||
taxes_ids = obj_tax_temp.generate_tax(cr, uid, ids, tax_templates_load, {}, context=context)
|
||||
obj_tax_temp.write(cr, uid , taxes_ids['taxes_id'].keys(), {'installable': True})
|
||||
return {}
|
||||
|
||||
account_tax_generate()
|
||||
|
|
Loading…
Reference in New Issue