Priyesh (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-company-currency into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-company-currency/+merge/122210

Hello,

1. In Set Accounting Options wizard, Added currency as default from User --> 
Company --> Country --> Currency otherwise 'EUR'.
2. Added onchange event for company to fetch related currency in Set Accounting 
Options wizard.
3. Overrided write method of company in product and purchase module to write 
new wizard currency into related pricelists.

Kindly review it.

Thanks,
Priyesh
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-company-currency/+merge/122210
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-company-currency.
=== modified file 'account/account.py'
--- account/account.py	2012-08-28 11:21:16 +0000
+++ account/account.py	2012-08-31 08:45:35 +0000
@@ -2997,6 +2997,7 @@
 
     _columns = {
         'company_id':fields.many2one('res.company', 'Company', required=True),
+        'currency_id': fields.many2one('res.currency', 'Currency', help="Currency as per company's country."),
         'only_one_chart_template': fields.boolean('Only One Chart Template Available'),
         'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
         'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True),
@@ -3007,6 +3008,13 @@
         'purchase_tax_rate': fields.float('Purchase Tax(%)'),
         'complete_tax_set': fields.boolean('Complete Set of Taxes', help='This boolean helps you to choose if you want to propose to the user to encode the sales and purchase rates or use the usual m2o fields. This last choice assumes that the set of tax defined for the chosen template is complete'),
     }
+    
+    def onchange_company_id(self, cr, uid, ids, company_id, context=None):
+        currency_id = False        
+        if company_id:
+            currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id
+        return {'value': {'currency_id': currency_id}}
+
     def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None):
         return {'value': {'purchase_tax_rate': rate or False}}
 
@@ -3037,6 +3045,13 @@
             res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
         if 'company_id' in fields:
             res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})
+        if 'currency_id' in fields:
+            company_id = res.get('company_id') or False
+            if company_id:
+                company_obj = self.pool.get('res.company')
+                country_id = company_obj.browse(cr, uid, company_id, context=context).country_id.id
+                currency_id = company_obj.on_change_country(cr, uid, company_id, country_id, context=context)['value']['currency_id']
+                res.update({'currency_id': currency_id})
 
         ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context)
         if ids:
@@ -3341,6 +3356,7 @@
         ir_values_obj = self.pool.get('ir.values')
         obj_wizard = self.browse(cr, uid, ids[0])
         company_id = obj_wizard.company_id.id
+        self.pool.get('res.company').write(cr, uid, [company_id], {'currency_id': obj_wizard.currency_id.id})
         # If the floats for sale/purchase rates have been filled, create templates from them
         self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context)
 

=== modified file 'account/account_view.xml'
--- account/account_view.xml	2012-08-28 11:21:16 +0000
+++ account/account_view.xml	2012-08-31 08:45:35 +0000
@@ -2371,8 +2371,10 @@
                     <field name="complete_tax_set" invisible="1"/>
                     <div groups="base.group_multi_company">
                         <label for="company_id"/>
-                        <field name="company_id" widget="selection"/> <!-- we assume that this wizard will be run only by administrators and as this field may cause problem if hidden (because of the default company of the user removed from the selection because already configured), we simply choosed to remove the group "multi company" of it -->
+                        <field name="company_id" widget="selection" on_change="onchange_company_id(company_id)"/> <!-- we assume that this wizard will be run only by administrators and as this field may cause problem if hidden (because of the default company of the user removed from the selection because already configured), we simply choosed to remove the group "multi company" of it -->
                     </div>
+                    <label for="currency_id"/>
+                    <field name="currency_id" />
                     <group>
                         <div attrs="{'invisible': [('only_one_chart_template','=',True)]}">
                             <label for="chart_template_id"/>

=== modified file 'account/res_config.py'
--- account/res_config.py	2012-08-09 12:04:09 +0000
+++ account/res_config.py	2012-08-31 08:45:35 +0000
@@ -145,42 +145,45 @@
 
     def onchange_company_id(self, cr, uid, ids, company_id):
         # update related fields
-        company = self.pool.get('res.company').browse(cr, uid, company_id)
-        has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
-        fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
-            [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
-             ('company_id', '=', company_id)])
-        values = {
-            'expects_chart_of_accounts': company.expects_chart_of_accounts,
-            'currency_id': company.currency_id.id,
-            'paypal_account': company.paypal_account,
-            'company_footer': company.rml_footer2,
-            'has_chart_of_accounts': has_chart_of_accounts,
-            'has_fiscal_year': bool(fiscalyear_count),
-            'chart_template_id': False,
-            'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
-        }
-        # update journals and sequences
-        for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
-            for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
-                values[journal_type + suffix] = False
-        journal_obj = self.pool.get('account.journal')
-        journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
-        for journal in journal_obj.browse(cr, uid, journal_ids):
-            if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
-                values.update({
-                    journal.type + '_journal_id': journal.id,
-                    journal.type + '_sequence_prefix': journal.sequence_id.prefix,
-                    journal.type + '_sequence_next': journal.sequence_id.number_next,
-                })
-        # update taxes
-        ir_values = self.pool.get('ir.values')
-        taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
-        supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
-        values.update({
-            'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
-            'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
-        })
+        values = {}
+        values['currency_id'] = False
+        if company_id:
+            company = self.pool.get('res.company').browse(cr, uid, company_id)
+            has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
+            fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
+                [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
+                 ('company_id', '=', company_id)])
+            values = {
+                'expects_chart_of_accounts': company.expects_chart_of_accounts,
+                'currency_id': company.currency_id.id,
+                'paypal_account': company.paypal_account,
+                'company_footer': company.rml_footer2,
+                'has_chart_of_accounts': has_chart_of_accounts,
+                'has_fiscal_year': bool(fiscalyear_count),
+                'chart_template_id': False,
+                'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
+            }
+            # update journals and sequences
+            for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
+                for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
+                    values[journal_type + suffix] = False
+            journal_obj = self.pool.get('account.journal')
+            journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
+            for journal in journal_obj.browse(cr, uid, journal_ids):
+                if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
+                    values.update({
+                        journal.type + '_journal_id': journal.id,
+                        journal.type + '_sequence_prefix': journal.sequence_id.prefix,
+                        journal.type + '_sequence_next': journal.sequence_id.number_next,
+                    })
+            # update taxes
+            ir_values = self.pool.get('ir.values')
+            taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
+            supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
+            values.update({
+                'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
+                'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
+            })
         return {'value': values}
 
     def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):

=== modified file 'l10n_syscohada/l10n_syscohada_data.xml'
--- l10n_syscohada/l10n_syscohada_data.xml	2012-06-28 06:40:05 +0000
+++ l10n_syscohada/l10n_syscohada_data.xml	2012-08-31 08:45:35 +0000
@@ -1816,15 +1816,15 @@
     #
     -->
 
-      <record id="base.CFA" model="res.currency">
+      <record id="base.XOF" model="res.currency">
         <field name="name">XOF</field>
         <field name="symbol">CFA</field>
         <field name="rounding">1</field>
         <field name="accuracy">4</field>
     </record>
-    <record id="base.rateCFA" model="res.currency.rate">
+    <record id="base.rateXOF" model="res.currency.rate">
            <field name="rate">655.957</field>
-           <field name="currency_id" ref="base.CFA"/>
+           <field name="currency_id" ref="base.XOF"/>
            <field eval="time.strftime('%Y-01-01')" name="name"/>
        </record>
            <!--

=== modified file 'product/pricelist.py'
--- product/pricelist.py	2012-08-14 14:10:40 +0000
+++ product/pricelist.py	2012-08-31 08:45:35 +0000
@@ -436,7 +436,22 @@
         return {}
 product_pricelist_item()
 
+class res_company(osv.osv):
+    _inherit = 'res.company'
+    
+    def _get_default_product_pricelist(self, cr, uid, context=None):
+        model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'list0')
+        return [pricelist_id]
 
+    def write(self, cr, uid, ids, vals, context=None):
+        res = super(res_company, self).write(cr, uid, ids, vals, context)
+        product_pricelist_obj = self.pool.get('product.pricelist')
+        currency = product_pricelist_obj._get_currency(cr, uid, context)
+        pricelist_ids = self._get_default_product_pricelist(cr, uid, context=context)
+        product_pricelist_obj.write(cr, uid, pricelist_ids, {'currency_id': currency}, context=context)
+        return res
+    
+res_company()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

=== modified file 'purchase/company.py'
--- purchase/company.py	2011-09-08 10:48:15 +0000
+++ purchase/company.py	2012-08-31 08:45:35 +0000
@@ -30,6 +30,12 @@
     _defaults = {
         'po_lead': lambda *a: 1.0,
     }
+    
+    def _get_default_product_pricelist(self, cr, uid, context=None):
+        pricelist_ids = super(company, self)._get_default_product_pricelist(cr, uid, context=context)
+        model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'purchase', 'list0')
+        return pricelist_ids + [pricelist_id]
+    
 company()
 
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to