Merge lp:~openerp-dev/openobject-addons/trunk-company-currency into lp:openobject-addons

Proposed by Priyesh (OpenERP)
Status: Merged
Merged at revision: 7375
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-company-currency
Merge into: lp:openobject-addons
Diff against target: 214 lines (+82/-40)
6 files modified
account/account.py (+16/-0)
account/account_view.xml (+3/-1)
account/res_config.py (+39/-36)
l10n_syscohada/l10n_syscohada_data.xml (+3/-3)
product/pricelist.py (+15/-0)
purchase/company.py (+6/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-company-currency
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+122210@code.launchpad.net

Description of the change

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

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
29972997
2998 _columns = {2998 _columns = {
2999 'company_id':fields.many2one('res.company', 'Company', required=True),2999 'company_id':fields.many2one('res.company', 'Company', required=True),
3000 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency as per company's country."),
3000 'only_one_chart_template': fields.boolean('Only One Chart Template Available'),3001 'only_one_chart_template': fields.boolean('Only One Chart Template Available'),
3001 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),3002 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
3002 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True),3003 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True),
@@ -3007,6 +3008,13 @@
3007 'purchase_tax_rate': fields.float('Purchase Tax(%)'),3008 'purchase_tax_rate': fields.float('Purchase Tax(%)'),
3008 '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'),3009 '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'),
3009 }3010 }
3011
3012 def onchange_company_id(self, cr, uid, ids, company_id, context=None):
3013 currency_id = False
3014 if company_id:
3015 currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id
3016 return {'value': {'currency_id': currency_id}}
3017
3010 def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None):3018 def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None):
3011 return {'value': {'purchase_tax_rate': rate or False}}3019 return {'value': {'purchase_tax_rate': rate or False}}
30123020
@@ -3037,6 +3045,13 @@
3037 res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})3045 res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
3038 if 'company_id' in fields:3046 if 'company_id' in fields:
3039 res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})3047 res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})
3048 if 'currency_id' in fields:
3049 company_id = res.get('company_id') or False
3050 if company_id:
3051 company_obj = self.pool.get('res.company')
3052 country_id = company_obj.browse(cr, uid, company_id, context=context).country_id.id
3053 currency_id = company_obj.on_change_country(cr, uid, company_id, country_id, context=context)['value']['currency_id']
3054 res.update({'currency_id': currency_id})
30403055
3041 ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context)3056 ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context)
3042 if ids:3057 if ids:
@@ -3341,6 +3356,7 @@
3341 ir_values_obj = self.pool.get('ir.values')3356 ir_values_obj = self.pool.get('ir.values')
3342 obj_wizard = self.browse(cr, uid, ids[0])3357 obj_wizard = self.browse(cr, uid, ids[0])
3343 company_id = obj_wizard.company_id.id3358 company_id = obj_wizard.company_id.id
3359 self.pool.get('res.company').write(cr, uid, [company_id], {'currency_id': obj_wizard.currency_id.id})
3344 # If the floats for sale/purchase rates have been filled, create templates from them3360 # If the floats for sale/purchase rates have been filled, create templates from them
3345 self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context)3361 self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context)
33463362
33473363
=== 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 @@
2371 <field name="complete_tax_set" invisible="1"/>2371 <field name="complete_tax_set" invisible="1"/>
2372 <div groups="base.group_multi_company">2372 <div groups="base.group_multi_company">
2373 <label for="company_id"/>2373 <label for="company_id"/>
2374 <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 -->2374 <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 -->
2375 </div>2375 </div>
2376 <label for="currency_id"/>
2377 <field name="currency_id" />
2376 <group>2378 <group>
2377 <div attrs="{'invisible': [('only_one_chart_template','=',True)]}">2379 <div attrs="{'invisible': [('only_one_chart_template','=',True)]}">
2378 <label for="chart_template_id"/>2380 <label for="chart_template_id"/>
23792381
=== 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 @@
145145
146 def onchange_company_id(self, cr, uid, ids, company_id):146 def onchange_company_id(self, cr, uid, ids, company_id):
147 # update related fields147 # update related fields
148 company = self.pool.get('res.company').browse(cr, uid, company_id)148 values = {}
149 has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)149 values['currency_id'] = False
150 fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,150 if company_id:
151 [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),151 company = self.pool.get('res.company').browse(cr, uid, company_id)
152 ('company_id', '=', company_id)])152 has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
153 values = {153 fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
154 'expects_chart_of_accounts': company.expects_chart_of_accounts,154 [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
155 'currency_id': company.currency_id.id,155 ('company_id', '=', company_id)])
156 'paypal_account': company.paypal_account,156 values = {
157 'company_footer': company.rml_footer2,157 'expects_chart_of_accounts': company.expects_chart_of_accounts,
158 'has_chart_of_accounts': has_chart_of_accounts,158 'currency_id': company.currency_id.id,
159 'has_fiscal_year': bool(fiscalyear_count),159 'paypal_account': company.paypal_account,
160 'chart_template_id': False,160 'company_footer': company.rml_footer2,
161 'tax_calculation_rounding_method': company.tax_calculation_rounding_method,161 'has_chart_of_accounts': has_chart_of_accounts,
162 }162 'has_fiscal_year': bool(fiscalyear_count),
163 # update journals and sequences163 'chart_template_id': False,
164 for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):164 'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
165 for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):165 }
166 values[journal_type + suffix] = False166 # update journals and sequences
167 journal_obj = self.pool.get('account.journal')167 for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
168 journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])168 for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
169 for journal in journal_obj.browse(cr, uid, journal_ids):169 values[journal_type + suffix] = False
170 if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):170 journal_obj = self.pool.get('account.journal')
171 values.update({171 journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
172 journal.type + '_journal_id': journal.id,172 for journal in journal_obj.browse(cr, uid, journal_ids):
173 journal.type + '_sequence_prefix': journal.sequence_id.prefix,173 if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
174 journal.type + '_sequence_next': journal.sequence_id.number_next,174 values.update({
175 })175 journal.type + '_journal_id': journal.id,
176 # update taxes176 journal.type + '_sequence_prefix': journal.sequence_id.prefix,
177 ir_values = self.pool.get('ir.values')177 journal.type + '_sequence_next': journal.sequence_id.number_next,
178 taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)178 })
179 supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)179 # update taxes
180 values.update({180 ir_values = self.pool.get('ir.values')
181 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,181 taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
182 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,182 supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
183 })183 values.update({
184 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
185 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
186 })
184 return {'value': values}187 return {'value': values}
185188
186 def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):189 def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):
187190
=== 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 @@
1816 #1816 #
1817 -->1817 -->
18181818
1819 <record id="base.CFA" model="res.currency">1819 <record id="base.XOF" model="res.currency">
1820 <field name="name">XOF</field>1820 <field name="name">XOF</field>
1821 <field name="symbol">CFA</field>1821 <field name="symbol">CFA</field>
1822 <field name="rounding">1</field>1822 <field name="rounding">1</field>
1823 <field name="accuracy">4</field>1823 <field name="accuracy">4</field>
1824 </record>1824 </record>
1825 <record id="base.rateCFA" model="res.currency.rate">1825 <record id="base.rateXOF" model="res.currency.rate">
1826 <field name="rate">655.957</field>1826 <field name="rate">655.957</field>
1827 <field name="currency_id" ref="base.CFA"/>1827 <field name="currency_id" ref="base.XOF"/>
1828 <field eval="time.strftime('%Y-01-01')" name="name"/>1828 <field eval="time.strftime('%Y-01-01')" name="name"/>
1829 </record>1829 </record>
1830 <!--1830 <!--
18311831
=== 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 @@
436 return {}436 return {}
437product_pricelist_item()437product_pricelist_item()
438438
439class res_company(osv.osv):
440 _inherit = 'res.company'
441
442 def _get_default_product_pricelist(self, cr, uid, context=None):
443 model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'list0')
444 return [pricelist_id]
439445
446 def write(self, cr, uid, ids, vals, context=None):
447 res = super(res_company, self).write(cr, uid, ids, vals, context)
448 product_pricelist_obj = self.pool.get('product.pricelist')
449 currency = product_pricelist_obj._get_currency(cr, uid, context)
450 pricelist_ids = self._get_default_product_pricelist(cr, uid, context=context)
451 product_pricelist_obj.write(cr, uid, pricelist_ids, {'currency_id': currency}, context=context)
452 return res
453
454res_company()
440455
441# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:456# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
442457
443458
=== 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 @@
30 _defaults = {30 _defaults = {
31 'po_lead': lambda *a: 1.0,31 'po_lead': lambda *a: 1.0,
32 }32 }
33
34 def _get_default_product_pricelist(self, cr, uid, context=None):
35 pricelist_ids = super(company, self)._get_default_product_pricelist(cr, uid, context=context)
36 model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'purchase', 'list0')
37 return pricelist_ids + [pricelist_id]
38
33company()39company()
3440
3541

Subscribers

People subscribed via source and target branches

to all changes: