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
1=== modified file 'account/account.py'
2--- account/account.py 2012-08-28 11:21:16 +0000
3+++ account/account.py 2012-08-31 08:45:35 +0000
4@@ -2997,6 +2997,7 @@
5
6 _columns = {
7 'company_id':fields.many2one('res.company', 'Company', required=True),
8+ 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency as per company's country."),
9 'only_one_chart_template': fields.boolean('Only One Chart Template Available'),
10 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
11 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True),
12@@ -3007,6 +3008,13 @@
13 'purchase_tax_rate': fields.float('Purchase Tax(%)'),
14 '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'),
15 }
16+
17+ def onchange_company_id(self, cr, uid, ids, company_id, context=None):
18+ currency_id = False
19+ if company_id:
20+ currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id
21+ return {'value': {'currency_id': currency_id}}
22+
23 def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None):
24 return {'value': {'purchase_tax_rate': rate or False}}
25
26@@ -3037,6 +3045,13 @@
27 res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
28 if 'company_id' in fields:
29 res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})
30+ if 'currency_id' in fields:
31+ company_id = res.get('company_id') or False
32+ if company_id:
33+ company_obj = self.pool.get('res.company')
34+ country_id = company_obj.browse(cr, uid, company_id, context=context).country_id.id
35+ currency_id = company_obj.on_change_country(cr, uid, company_id, country_id, context=context)['value']['currency_id']
36+ res.update({'currency_id': currency_id})
37
38 ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context)
39 if ids:
40@@ -3341,6 +3356,7 @@
41 ir_values_obj = self.pool.get('ir.values')
42 obj_wizard = self.browse(cr, uid, ids[0])
43 company_id = obj_wizard.company_id.id
44+ self.pool.get('res.company').write(cr, uid, [company_id], {'currency_id': obj_wizard.currency_id.id})
45 # If the floats for sale/purchase rates have been filled, create templates from them
46 self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context)
47
48
49=== modified file 'account/account_view.xml'
50--- account/account_view.xml 2012-08-28 11:21:16 +0000
51+++ account/account_view.xml 2012-08-31 08:45:35 +0000
52@@ -2371,8 +2371,10 @@
53 <field name="complete_tax_set" invisible="1"/>
54 <div groups="base.group_multi_company">
55 <label for="company_id"/>
56- <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 -->
57+ <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 -->
58 </div>
59+ <label for="currency_id"/>
60+ <field name="currency_id" />
61 <group>
62 <div attrs="{'invisible': [('only_one_chart_template','=',True)]}">
63 <label for="chart_template_id"/>
64
65=== modified file 'account/res_config.py'
66--- account/res_config.py 2012-08-09 12:04:09 +0000
67+++ account/res_config.py 2012-08-31 08:45:35 +0000
68@@ -145,42 +145,45 @@
69
70 def onchange_company_id(self, cr, uid, ids, company_id):
71 # update related fields
72- company = self.pool.get('res.company').browse(cr, uid, company_id)
73- has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
74- fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
75- [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
76- ('company_id', '=', company_id)])
77- values = {
78- 'expects_chart_of_accounts': company.expects_chart_of_accounts,
79- 'currency_id': company.currency_id.id,
80- 'paypal_account': company.paypal_account,
81- 'company_footer': company.rml_footer2,
82- 'has_chart_of_accounts': has_chart_of_accounts,
83- 'has_fiscal_year': bool(fiscalyear_count),
84- 'chart_template_id': False,
85- 'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
86- }
87- # update journals and sequences
88- for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
89- for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
90- values[journal_type + suffix] = False
91- journal_obj = self.pool.get('account.journal')
92- journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
93- for journal in journal_obj.browse(cr, uid, journal_ids):
94- if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
95- values.update({
96- journal.type + '_journal_id': journal.id,
97- journal.type + '_sequence_prefix': journal.sequence_id.prefix,
98- journal.type + '_sequence_next': journal.sequence_id.number_next,
99- })
100- # update taxes
101- ir_values = self.pool.get('ir.values')
102- taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
103- supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
104- values.update({
105- 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
106- 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
107- })
108+ values = {}
109+ values['currency_id'] = False
110+ if company_id:
111+ company = self.pool.get('res.company').browse(cr, uid, company_id)
112+ has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
113+ fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
114+ [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
115+ ('company_id', '=', company_id)])
116+ values = {
117+ 'expects_chart_of_accounts': company.expects_chart_of_accounts,
118+ 'currency_id': company.currency_id.id,
119+ 'paypal_account': company.paypal_account,
120+ 'company_footer': company.rml_footer2,
121+ 'has_chart_of_accounts': has_chart_of_accounts,
122+ 'has_fiscal_year': bool(fiscalyear_count),
123+ 'chart_template_id': False,
124+ 'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
125+ }
126+ # update journals and sequences
127+ for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
128+ for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
129+ values[journal_type + suffix] = False
130+ journal_obj = self.pool.get('account.journal')
131+ journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
132+ for journal in journal_obj.browse(cr, uid, journal_ids):
133+ if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
134+ values.update({
135+ journal.type + '_journal_id': journal.id,
136+ journal.type + '_sequence_prefix': journal.sequence_id.prefix,
137+ journal.type + '_sequence_next': journal.sequence_id.number_next,
138+ })
139+ # update taxes
140+ ir_values = self.pool.get('ir.values')
141+ taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
142+ supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
143+ values.update({
144+ 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
145+ 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
146+ })
147 return {'value': values}
148
149 def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):
150
151=== modified file 'l10n_syscohada/l10n_syscohada_data.xml'
152--- l10n_syscohada/l10n_syscohada_data.xml 2012-06-28 06:40:05 +0000
153+++ l10n_syscohada/l10n_syscohada_data.xml 2012-08-31 08:45:35 +0000
154@@ -1816,15 +1816,15 @@
155 #
156 -->
157
158- <record id="base.CFA" model="res.currency">
159+ <record id="base.XOF" model="res.currency">
160 <field name="name">XOF</field>
161 <field name="symbol">CFA</field>
162 <field name="rounding">1</field>
163 <field name="accuracy">4</field>
164 </record>
165- <record id="base.rateCFA" model="res.currency.rate">
166+ <record id="base.rateXOF" model="res.currency.rate">
167 <field name="rate">655.957</field>
168- <field name="currency_id" ref="base.CFA"/>
169+ <field name="currency_id" ref="base.XOF"/>
170 <field eval="time.strftime('%Y-01-01')" name="name"/>
171 </record>
172 <!--
173
174=== modified file 'product/pricelist.py'
175--- product/pricelist.py 2012-08-14 14:10:40 +0000
176+++ product/pricelist.py 2012-08-31 08:45:35 +0000
177@@ -436,7 +436,22 @@
178 return {}
179 product_pricelist_item()
180
181+class res_company(osv.osv):
182+ _inherit = 'res.company'
183+
184+ def _get_default_product_pricelist(self, cr, uid, context=None):
185+ model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'list0')
186+ return [pricelist_id]
187
188+ def write(self, cr, uid, ids, vals, context=None):
189+ res = super(res_company, self).write(cr, uid, ids, vals, context)
190+ product_pricelist_obj = self.pool.get('product.pricelist')
191+ currency = product_pricelist_obj._get_currency(cr, uid, context)
192+ pricelist_ids = self._get_default_product_pricelist(cr, uid, context=context)
193+ product_pricelist_obj.write(cr, uid, pricelist_ids, {'currency_id': currency}, context=context)
194+ return res
195+
196+res_company()
197
198 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
199
200
201=== modified file 'purchase/company.py'
202--- purchase/company.py 2011-09-08 10:48:15 +0000
203+++ purchase/company.py 2012-08-31 08:45:35 +0000
204@@ -30,6 +30,12 @@
205 _defaults = {
206 'po_lead': lambda *a: 1.0,
207 }
208+
209+ def _get_default_product_pricelist(self, cr, uid, context=None):
210+ pricelist_ids = super(company, self)._get_default_product_pricelist(cr, uid, context=context)
211+ model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'purchase', 'list0')
212+ return pricelist_ids + [pricelist_id]
213+
214 company()
215
216

Subscribers

People subscribed via source and target branches

to all changes: