← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/niv-dev-addons into lp:openobject-addons

 

Nicolas Vanhoren has proposed merging lp:~openerp-dev/openobject-addons/niv-dev-addons into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)


Added new fields in the wizard used to create chart of account from a chart template. These fields allows to set a default value for the taxes account of new products.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/niv-dev-addons/+merge/38558
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/niv-dev-addons.
=== modified file 'account/account.py'
--- account/account.py	2010-10-14 04:17:25 +0000
+++ account/account.py	2010-10-15 15:52:44 +0000
@@ -2537,7 +2537,22 @@
         'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Bank Accounts', required=True),
         'code_digits':fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"),
         'seq_journal':fields.boolean('Separated Journal Sequences', help="Check this box if you want to use a different sequence for each created journal. Otherwise, all will use the same sequence."),
+        "sale_tax": fields.many2one("account.tax.template", "Sale Tax"),
+        "purchase_tax": fields.many2one("account.tax.template", "Purchase Tax"),
     }
+    def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None):
+        res = {}
+        res['value'] = {}
+        res['value']["sale_tax"] = False
+        res['value']["purchase_tax"] = False
+        if chart_template_id:
+            ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
+                                          , "=", chart_template_id)], order="sequence")
+            if len(ids) > 0:
+                id=ids[0]
+                res['value']["sale_tax"] = id
+                res['value']["purchase_tax"] = id
+        return res
 
     def _get_chart(self, cr, uid, context={}):
         ids = self.pool.get('account.chart.template').search(cr, uid, [], context=context)
@@ -2553,6 +2568,7 @@
 
     def execute(self, cr, uid, ids, context=None):
         obj_multi = self.browse(cr, uid, ids[0])
+        
         obj_acc = self.pool.get('account.account')
         obj_acc_tax = self.pool.get('account.tax')
         obj_journal = self.pool.get('account.journal')
@@ -2591,6 +2607,7 @@
             tax_code_template_ref[tax_code_template.id] = new_tax_code
 
         #create all the tax
+        tax_template_to_tax = {}
         for tax in obj_multi.chart_template_id.tax_template_ids:
             #create it
             vals_tax = {
@@ -2619,8 +2636,10 @@
                 'type_tax_use': tax.type_tax_use
             }
             new_tax = obj_acc_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,
             }
@@ -2842,6 +2861,12 @@
                         'position_id': new_fp,
                     }
                     obj_ac_fp.create(cr, uid, vals_acc)
+        
+        ir_values = self.pool.get('ir.values')
+        ir_values.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]])
+        ir_values.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]])
 
 wizard_multi_charts_accounts()
 

=== modified file 'account/account_view.xml'
--- account/account_view.xml	2010-10-14 18:02:00 +0000
+++ account/account_view.xml	2010-10-15 15:52:44 +0000
@@ -2412,8 +2412,11 @@
                 <group string="res_config_contents" position="replace">
                   <field name="company_id" widget="selection"/>
                   <field name ="code_digits" />
-                  <field name="chart_template_id" widget="selection"/>
+                  <field name="chart_template_id" widget="selection"
+                  		on_change="onchange_chart_template_id(chart_template_id)"/>
                   <field name ="seq_journal" />
+                  <field name="sale_tax" domain="[('chart_template_id', '=', chart_template_id),('parent_id','=',False)]"/>
+                  <field name="purchase_tax" domain="[('chart_template_id', '=', chart_template_id),('parent_id','=',False)]"/>
                   <field colspan="4" mode="tree" name="bank_accounts_id"
                          nolabel="1" widget="one2many_list">
                     <form string="Bank Information">


Follow ups