Merge lp:~openerp-dev/openobject-addons/trunk-company-currency into lp:openobject-addons
- trunk-company-currency
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenERP Core Team | Pending | ||
Review via email:
|
Commit message
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 | 2997 | 2997 | ||
6 | 2998 | _columns = { | 2998 | _columns = { |
7 | 2999 | 'company_id':fields.many2one('res.company', 'Company', required=True), | 2999 | 'company_id':fields.many2one('res.company', 'Company', required=True), |
8 | 3000 | 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency as per company's country."), | ||
9 | 3000 | 'only_one_chart_template': fields.boolean('Only One Chart Template Available'), | 3001 | 'only_one_chart_template': fields.boolean('Only One Chart Template Available'), |
10 | 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), |
11 | 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), |
12 | @@ -3007,6 +3008,13 @@ | |||
13 | 3007 | 'purchase_tax_rate': fields.float('Purchase Tax(%)'), | 3008 | 'purchase_tax_rate': fields.float('Purchase Tax(%)'), |
14 | 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'), |
15 | 3009 | } | 3010 | } |
16 | 3011 | |||
17 | 3012 | def onchange_company_id(self, cr, uid, ids, company_id, context=None): | ||
18 | 3013 | currency_id = False | ||
19 | 3014 | if company_id: | ||
20 | 3015 | currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id | ||
21 | 3016 | return {'value': {'currency_id': currency_id}} | ||
22 | 3017 | |||
23 | 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): |
24 | 3011 | return {'value': {'purchase_tax_rate': rate or False}} | 3019 | return {'value': {'purchase_tax_rate': rate or False}} |
25 | 3012 | 3020 | ||
26 | @@ -3037,6 +3045,13 @@ | |||
27 | 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'}]}) |
28 | 3038 | if 'company_id' in fields: | 3046 | if 'company_id' in fields: |
29 | 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}) |
30 | 3048 | if 'currency_id' in fields: | ||
31 | 3049 | company_id = res.get('company_id') or False | ||
32 | 3050 | if company_id: | ||
33 | 3051 | company_obj = self.pool.get('res.company') | ||
34 | 3052 | country_id = company_obj.browse(cr, uid, company_id, context=context).country_id.id | ||
35 | 3053 | currency_id = company_obj.on_change_country(cr, uid, company_id, country_id, context=context)['value']['currency_id'] | ||
36 | 3054 | res.update({'currency_id': currency_id}) | ||
37 | 3040 | 3055 | ||
38 | 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) |
39 | 3042 | if ids: | 3057 | if ids: |
40 | @@ -3341,6 +3356,7 @@ | |||
41 | 3341 | ir_values_obj = self.pool.get('ir.values') | 3356 | ir_values_obj = self.pool.get('ir.values') |
42 | 3342 | obj_wizard = self.browse(cr, uid, ids[0]) | 3357 | obj_wizard = self.browse(cr, uid, ids[0]) |
43 | 3343 | company_id = obj_wizard.company_id.id | 3358 | company_id = obj_wizard.company_id.id |
44 | 3359 | self.pool.get('res.company').write(cr, uid, [company_id], {'currency_id': obj_wizard.currency_id.id}) | ||
45 | 3344 | # If the floats for sale/purchase rates have been filled, create templates from them | 3360 | # If the floats for sale/purchase rates have been filled, create templates from them |
46 | 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) |
47 | 3346 | 3362 | ||
48 | 3347 | 3363 | ||
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 | 2371 | <field name="complete_tax_set" invisible="1"/> | 2371 | <field name="complete_tax_set" invisible="1"/> |
54 | 2372 | <div groups="base.group_multi_company"> | 2372 | <div groups="base.group_multi_company"> |
55 | 2373 | <label for="company_id"/> | 2373 | <label for="company_id"/> |
57 | 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 --> |
58 | 2375 | </div> | 2375 | </div> |
59 | 2376 | <label for="currency_id"/> | ||
60 | 2377 | <field name="currency_id" /> | ||
61 | 2376 | <group> | 2378 | <group> |
62 | 2377 | <div attrs="{'invisible': [('only_one_chart_template','=',True)]}"> | 2379 | <div attrs="{'invisible': [('only_one_chart_template','=',True)]}"> |
63 | 2378 | <label for="chart_template_id"/> | 2380 | <label for="chart_template_id"/> |
64 | 2379 | 2381 | ||
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 | 145 | 145 | ||
70 | 146 | def onchange_company_id(self, cr, uid, ids, company_id): | 146 | def onchange_company_id(self, cr, uid, ids, company_id): |
71 | 147 | # update related fields | 147 | # update related fields |
108 | 148 | company = self.pool.get('res.company').browse(cr, uid, company_id) | 148 | values = {} |
109 | 149 | has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid) | 149 | values['currency_id'] = False |
110 | 150 | fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid, | 150 | if company_id: |
111 | 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) |
112 | 152 | ('company_id', '=', company_id)]) | 152 | has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid) |
113 | 153 | values = { | 153 | fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid, |
114 | 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')), |
115 | 155 | 'currency_id': company.currency_id.id, | 155 | ('company_id', '=', company_id)]) |
116 | 156 | 'paypal_account': company.paypal_account, | 156 | values = { |
117 | 157 | 'company_footer': company.rml_footer2, | 157 | 'expects_chart_of_accounts': company.expects_chart_of_accounts, |
118 | 158 | 'has_chart_of_accounts': has_chart_of_accounts, | 158 | 'currency_id': company.currency_id.id, |
119 | 159 | 'has_fiscal_year': bool(fiscalyear_count), | 159 | 'paypal_account': company.paypal_account, |
120 | 160 | 'chart_template_id': False, | 160 | 'company_footer': company.rml_footer2, |
121 | 161 | 'tax_calculation_rounding_method': company.tax_calculation_rounding_method, | 161 | 'has_chart_of_accounts': has_chart_of_accounts, |
122 | 162 | } | 162 | 'has_fiscal_year': bool(fiscalyear_count), |
123 | 163 | # update journals and sequences | 163 | 'chart_template_id': False, |
124 | 164 | for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'): | 164 | 'tax_calculation_rounding_method': company.tax_calculation_rounding_method, |
125 | 165 | for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'): | 165 | } |
126 | 166 | values[journal_type + suffix] = False | 166 | # update journals and sequences |
127 | 167 | journal_obj = self.pool.get('account.journal') | 167 | for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'): |
128 | 168 | journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)]) | 168 | for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'): |
129 | 169 | for journal in journal_obj.browse(cr, uid, journal_ids): | 169 | values[journal_type + suffix] = False |
130 | 170 | if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'): | 170 | journal_obj = self.pool.get('account.journal') |
131 | 171 | values.update({ | 171 | journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)]) |
132 | 172 | journal.type + '_journal_id': journal.id, | 172 | for journal in journal_obj.browse(cr, uid, journal_ids): |
133 | 173 | journal.type + '_sequence_prefix': journal.sequence_id.prefix, | 173 | if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'): |
134 | 174 | journal.type + '_sequence_next': journal.sequence_id.number_next, | 174 | values.update({ |
135 | 175 | }) | 175 | journal.type + '_journal_id': journal.id, |
136 | 176 | # update taxes | 176 | journal.type + '_sequence_prefix': journal.sequence_id.prefix, |
137 | 177 | ir_values = self.pool.get('ir.values') | 177 | journal.type + '_sequence_next': journal.sequence_id.number_next, |
138 | 178 | taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id) | 178 | }) |
139 | 179 | supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id) | 179 | # update taxes |
140 | 180 | values.update({ | 180 | ir_values = self.pool.get('ir.values') |
141 | 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) |
142 | 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) |
143 | 183 | }) | 183 | values.update({ |
144 | 184 | 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id, | ||
145 | 185 | 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id, | ||
146 | 186 | }) | ||
147 | 184 | return {'value': values} | 187 | return {'value': values} |
148 | 185 | 188 | ||
149 | 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): |
150 | 187 | 190 | ||
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 | 1816 | # | 1816 | # |
156 | 1817 | --> | 1817 | --> |
157 | 1818 | 1818 | ||
159 | 1819 | <record id="base.CFA" model="res.currency"> | 1819 | <record id="base.XOF" model="res.currency"> |
160 | 1820 | <field name="name">XOF</field> | 1820 | <field name="name">XOF</field> |
161 | 1821 | <field name="symbol">CFA</field> | 1821 | <field name="symbol">CFA</field> |
162 | 1822 | <field name="rounding">1</field> | 1822 | <field name="rounding">1</field> |
163 | 1823 | <field name="accuracy">4</field> | 1823 | <field name="accuracy">4</field> |
164 | 1824 | </record> | 1824 | </record> |
166 | 1825 | <record id="base.rateCFA" model="res.currency.rate"> | 1825 | <record id="base.rateXOF" model="res.currency.rate"> |
167 | 1826 | <field name="rate">655.957</field> | 1826 | <field name="rate">655.957</field> |
169 | 1827 | <field name="currency_id" ref="base.CFA"/> | 1827 | <field name="currency_id" ref="base.XOF"/> |
170 | 1828 | <field eval="time.strftime('%Y-01-01')" name="name"/> | 1828 | <field eval="time.strftime('%Y-01-01')" name="name"/> |
171 | 1829 | </record> | 1829 | </record> |
172 | 1830 | <!-- | 1830 | <!-- |
173 | 1831 | 1831 | ||
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 | 436 | return {} | 436 | return {} |
179 | 437 | product_pricelist_item() | 437 | product_pricelist_item() |
180 | 438 | 438 | ||
181 | 439 | class res_company(osv.osv): | ||
182 | 440 | _inherit = 'res.company' | ||
183 | 441 | |||
184 | 442 | def _get_default_product_pricelist(self, cr, uid, context=None): | ||
185 | 443 | model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'list0') | ||
186 | 444 | return [pricelist_id] | ||
187 | 439 | 445 | ||
188 | 446 | def write(self, cr, uid, ids, vals, context=None): | ||
189 | 447 | res = super(res_company, self).write(cr, uid, ids, vals, context) | ||
190 | 448 | product_pricelist_obj = self.pool.get('product.pricelist') | ||
191 | 449 | currency = product_pricelist_obj._get_currency(cr, uid, context) | ||
192 | 450 | pricelist_ids = self._get_default_product_pricelist(cr, uid, context=context) | ||
193 | 451 | product_pricelist_obj.write(cr, uid, pricelist_ids, {'currency_id': currency}, context=context) | ||
194 | 452 | return res | ||
195 | 453 | |||
196 | 454 | res_company() | ||
197 | 440 | 455 | ||
198 | 441 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | 456 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
199 | 442 | 457 | ||
200 | 443 | 458 | ||
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 | 30 | _defaults = { | 30 | _defaults = { |
206 | 31 | 'po_lead': lambda *a: 1.0, | 31 | 'po_lead': lambda *a: 1.0, |
207 | 32 | } | 32 | } |
208 | 33 | |||
209 | 34 | def _get_default_product_pricelist(self, cr, uid, context=None): | ||
210 | 35 | pricelist_ids = super(company, self)._get_default_product_pricelist(cr, uid, context=context) | ||
211 | 36 | model, pricelist_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'purchase', 'list0') | ||
212 | 37 | return pricelist_ids + [pricelist_id] | ||
213 | 38 | |||
214 | 33 | company() | 39 | company() |
215 | 34 | 40 | ||
216 | 35 | 41 |