Merge lp:~camptocamp/c2c-addons/add-alternate-currency-lep into lp:c2c-addons
- add-alternate-currency-lep
- Merge into 7.0
Proposed by
Leonardo Pistone
Status: | Needs review |
---|---|
Proposed branch: | lp:~camptocamp/c2c-addons/add-alternate-currency-lep |
Merge into: | lp:c2c-addons |
Diff against target: |
1019 lines (+903/-0) 21 files modified
invoice_alternate_currency/__init__.py (+22/-0) invoice_alternate_currency/__openerp__.py (+55/-0) invoice_alternate_currency/model/__init__.py (+22/-0) invoice_alternate_currency/model/invoice.py (+90/-0) invoice_alternate_currency/test/invoice_alternate_currency.yml (+35/-0) invoice_alternate_currency/test/set_rate.yml (+10/-0) invoice_alternate_currency/view/invoice.xml (+81/-0) purchase_alternate_currency/__init__.py (+22/-0) purchase_alternate_currency/__openerp__.py (+54/-0) purchase_alternate_currency/model/__init__.py (+22/-0) purchase_alternate_currency/model/purchase.py (+90/-0) purchase_alternate_currency/test/purchase_alternate_currency.yml (+35/-0) purchase_alternate_currency/test/set_rate.yml (+10/-0) purchase_alternate_currency/view/purchase.xml (+54/-0) sale_alternate_currency/__init__.py (+22/-0) sale_alternate_currency/__openerp__.py (+54/-0) sale_alternate_currency/model/__init__.py (+22/-0) sale_alternate_currency/model/sale.py (+89/-0) sale_alternate_currency/test/sale_alternate_currency.yml (+36/-0) sale_alternate_currency/test/set_rate.yml (+10/-0) sale_alternate_currency/view/sale.xml (+68/-0) |
To merge this branch: | bzr merge lp:~camptocamp/c2c-addons/add-alternate-currency-lep |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Leonardo Pistone | Needs Fixing | ||
Review via email: mp+227373@code.launchpad.net |
Commit message
Description of the change
2 new modules: sale_alternate_
I'm not proposing these to OCA because they have hardcoded currencies.
To post a comment you must log in.
- 15. By Matthieu Dietrich @ camptocamp
-
[ADD] added invoice untaxed totals + corrected a few columns
Revision history for this message
Leonardo Pistone (lepistone) wrote : | # |
Same things for the tests. Can you please fix those and check that they pass?
review:
Needs Fixing
Unmerged revisions
- 15. By Matthieu Dietrich @ camptocamp
-
[ADD] added invoice untaxed totals + corrected a few columns
- 14. By Leonardo Pistone
-
sale_alternate_
currency: don'y show in draft - 13. By Leonardo Pistone
-
purchase_
alternate_ currency: don't show in draft - 12. By Leonardo Pistone
-
add purchase_
alternate_ currency - 11. By Leonardo Pistone
-
add totals to tree view, change labels
- 10. By Leonardo Pistone
-
add module sale_alternate_
currency
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'invoice_alternate_currency' | |||
2 | === added file 'invoice_alternate_currency/__init__.py' | |||
3 | --- invoice_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ invoice_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000 | |||
5 | @@ -0,0 +1,22 @@ | |||
6 | 1 | # -*- coding: utf-8 -*- | ||
7 | 2 | ############################################################################## | ||
8 | 3 | # | ||
9 | 4 | # Author: Matthieu Dietrich | ||
10 | 5 | # Copyright 2014 Camptocamp SA | ||
11 | 6 | # | ||
12 | 7 | # This program is free software: you can redistribute it and/or modify | ||
13 | 8 | # it under the terms of the GNU Affero General Public License as | ||
14 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
15 | 10 | # License, or (at your option) any later version. | ||
16 | 11 | # | ||
17 | 12 | # This program is distributed in the hope that it will be useful, | ||
18 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | 15 | # GNU Affero General Public License for more details. | ||
21 | 16 | # | ||
22 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
23 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
24 | 19 | # | ||
25 | 20 | ############################################################################## | ||
26 | 21 | |||
27 | 22 | from . import model # noqa | ||
28 | 0 | 23 | ||
29 | === added file 'invoice_alternate_currency/__openerp__.py' | |||
30 | --- invoice_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
31 | +++ invoice_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000 | |||
32 | @@ -0,0 +1,55 @@ | |||
33 | 1 | # -*- coding: utf-8 -*- | ||
34 | 2 | ############################################################################## | ||
35 | 3 | # | ||
36 | 4 | # Author: Matthieu Dietrich | ||
37 | 5 | # Copyright 2014 Camptocamp SA | ||
38 | 6 | # | ||
39 | 7 | # This program is free software: you can redistribute it and/or modify | ||
40 | 8 | # it under the terms of the GNU Affero General Public License as | ||
41 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
42 | 10 | # License, or (at your option) any later version. | ||
43 | 11 | # | ||
44 | 12 | # This program is distributed in the hope that it will be useful, | ||
45 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
46 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
47 | 15 | # GNU Affero General Public License for more details. | ||
48 | 16 | # | ||
49 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
50 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
51 | 19 | # | ||
52 | 20 | ############################################################################## | ||
53 | 21 | { | ||
54 | 22 | 'name': 'Invoice Alternate Currency', | ||
55 | 23 | 'version': '1.0', | ||
56 | 24 | 'category': 'Generic Modules/Purchase', | ||
57 | 25 | 'description': """ | ||
58 | 26 | Purchase Alternate Currency | ||
59 | 27 | =========================== | ||
60 | 28 | |||
61 | 29 | This module shows the value untaxed total of the invoice in two, fixed | ||
62 | 30 | alternate currencies. These two currencies are hardcoded. | ||
63 | 31 | |||
64 | 32 | The totals are written at the moment when the invoice is confirmed. The rate | ||
65 | 33 | used is stored, too. | ||
66 | 34 | |||
67 | 35 | Contributors | ||
68 | 36 | ------------ | ||
69 | 37 | |||
70 | 38 | * Leonardo Pistone <leonardo.pistone@camptocamp.com> | ||
71 | 39 | * Matthieu Dietrich <matthieu.dietrich@camptocamp.com> | ||
72 | 40 | |||
73 | 41 | """, | ||
74 | 42 | 'author': 'Camptocamp', | ||
75 | 43 | 'depends': ['account'], | ||
76 | 44 | 'website': 'http://www.camptocamp.com', | ||
77 | 45 | 'data': [ | ||
78 | 46 | 'view/invoice.xml', | ||
79 | 47 | ], | ||
80 | 48 | 'test': [ | ||
81 | 49 | 'test/set_rate.yml', | ||
82 | 50 | 'test/invoice_alternate_currency.yml', | ||
83 | 51 | ], | ||
84 | 52 | 'demo': [], | ||
85 | 53 | 'installable': True, | ||
86 | 54 | 'active': False, | ||
87 | 55 | } | ||
88 | 0 | 56 | ||
89 | === added directory 'invoice_alternate_currency/model' | |||
90 | === added file 'invoice_alternate_currency/model/__init__.py' | |||
91 | --- invoice_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
92 | +++ invoice_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000 | |||
93 | @@ -0,0 +1,22 @@ | |||
94 | 1 | # -*- coding: utf-8 -*- | ||
95 | 2 | ############################################################################## | ||
96 | 3 | # | ||
97 | 4 | # Author: Matthieu Dietrich | ||
98 | 5 | # Copyright 2014 Camptocamp SA | ||
99 | 6 | # | ||
100 | 7 | # This program is free software: you can redistribute it and/or modify | ||
101 | 8 | # it under the terms of the GNU Affero General Public License as | ||
102 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
103 | 10 | # License, or (at your option) any later version. | ||
104 | 11 | # | ||
105 | 12 | # This program is distributed in the hope that it will be useful, | ||
106 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
107 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
108 | 15 | # GNU Affero General Public License for more details. | ||
109 | 16 | # | ||
110 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
111 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
112 | 19 | # | ||
113 | 20 | ############################################################################## | ||
114 | 21 | |||
115 | 22 | from . import invoice # noqa | ||
116 | 0 | 23 | ||
117 | === added file 'invoice_alternate_currency/model/invoice.py' | |||
118 | --- invoice_alternate_currency/model/invoice.py 1970-01-01 00:00:00 +0000 | |||
119 | +++ invoice_alternate_currency/model/invoice.py 2014-07-23 10:29:51 +0000 | |||
120 | @@ -0,0 +1,90 @@ | |||
121 | 1 | # -*- coding: utf-8 -*- | ||
122 | 2 | ############################################################################## | ||
123 | 3 | # | ||
124 | 4 | # Author: Matthieu Dietrich | ||
125 | 5 | # Copyright 2014 Camptocamp SA | ||
126 | 6 | # | ||
127 | 7 | # This program is free software: you can redistribute it and/or modify | ||
128 | 8 | # it under the terms of the GNU Affero General Public License as | ||
129 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
130 | 10 | # License, or (at your option) any later version. | ||
131 | 11 | # | ||
132 | 12 | # This program is distributed in the hope that it will be useful, | ||
133 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
134 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
135 | 15 | # GNU Affero General Public License for more details. | ||
136 | 16 | # | ||
137 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
138 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
139 | 19 | # | ||
140 | 20 | ############################################################################## | ||
141 | 21 | |||
142 | 22 | from openerp.osv import orm, fields | ||
143 | 23 | import openerp.addons.decimal_precision as dp | ||
144 | 24 | |||
145 | 25 | |||
146 | 26 | class AccountInvoice(orm.Model): | ||
147 | 27 | _inherit = 'account.invoice' | ||
148 | 28 | |||
149 | 29 | _columns = { | ||
150 | 30 | 'rate_eur': fields.float( | ||
151 | 31 | 'EUR Rate when confirmed', digits=(12, 6), | ||
152 | 32 | readonly=True, | ||
153 | 33 | help='The rate used when the order was confirmed'), | ||
154 | 34 | 'rate_usd': fields.float( | ||
155 | 35 | 'USD Rate when confirmed', digits=(12, 6), | ||
156 | 36 | readonly=True, | ||
157 | 37 | help='The rate used when the order was confirmed'), | ||
158 | 38 | 'amount_untaxed_eur': fields.float( | ||
159 | 39 | 'EUR Untaxed', | ||
160 | 40 | digits_compute=dp.get_precision('Account'), | ||
161 | 41 | readonly=True, | ||
162 | 42 | help='Untaxed Amount in EUR ' | ||
163 | 43 | 'computed at when the order is confirmed', | ||
164 | 44 | ), | ||
165 | 45 | 'amount_untaxed_usd': fields.float( | ||
166 | 46 | 'USD Untaxed', | ||
167 | 47 | digits_compute=dp.get_precision('Account'), | ||
168 | 48 | readonly=True, | ||
169 | 49 | help='Untaxed Amount in USD ' | ||
170 | 50 | 'computed at when the order is confirmed', | ||
171 | 51 | ), | ||
172 | 52 | } | ||
173 | 53 | |||
174 | 54 | def invoice_validate(self, cr, uid, ids, context=None): | ||
175 | 55 | super(AccountInvoice, self).invoice_validate(cr, uid, ids, context) | ||
176 | 56 | |||
177 | 57 | currency_obj = self.pool['res.currency'] | ||
178 | 58 | mod_obj = self.pool['ir.model.data'] | ||
179 | 59 | eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1] | ||
180 | 60 | usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1] | ||
181 | 61 | eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id], | ||
182 | 62 | context=context) | ||
183 | 63 | |||
184 | 64 | for invoice in self.browse(cr, uid, ids, context=context): | ||
185 | 65 | invoice.write({ | ||
186 | 66 | 'rate_eur': currency_obj._get_conversion_rate( | ||
187 | 67 | cr, uid, invoice.currency_id, eur, context=context), | ||
188 | 68 | 'rate_usd': currency_obj._get_conversion_rate( | ||
189 | 69 | cr, uid, invoice.currency_id, usd, context=context), | ||
190 | 70 | 'amount_untaxed_eur': currency_obj.compute( | ||
191 | 71 | cr, uid, invoice.currency_id.id, eur_id, | ||
192 | 72 | invoice.amount_untaxed, context=context), | ||
193 | 73 | 'amount_untaxed_usd': currency_obj.compute( | ||
194 | 74 | cr, uid, invoice.currency_id.id, usd_id, | ||
195 | 75 | invoice.amount_untaxed, context=context), | ||
196 | 76 | }) | ||
197 | 77 | |||
198 | 78 | return True | ||
199 | 79 | |||
200 | 80 | def copy_data(self, cr, uid, id, default, context): | ||
201 | 81 | if default is None: | ||
202 | 82 | default = {} | ||
203 | 83 | |||
204 | 84 | default.update({ | ||
205 | 85 | field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur', | ||
206 | 86 | 'rate_usd', 'amount_untaxed_usd') | ||
207 | 87 | }) | ||
208 | 88 | |||
209 | 89 | return super(AccountInvoice, self).copy_data(cr, uid, id, default, | ||
210 | 90 | context) | ||
211 | 0 | 91 | ||
212 | === added directory 'invoice_alternate_currency/test' | |||
213 | === added file 'invoice_alternate_currency/test/invoice_alternate_currency.yml' | |||
214 | --- invoice_alternate_currency/test/invoice_alternate_currency.yml 1970-01-01 00:00:00 +0000 | |||
215 | +++ invoice_alternate_currency/test/invoice_alternate_currency.yml 2014-07-23 10:29:51 +0000 | |||
216 | @@ -0,0 +1,35 @@ | |||
217 | 1 | - | ||
218 | 2 | I change the currency of the default pricelist to PLN | ||
219 | 3 | - | ||
220 | 4 | !record {model: product.pricelist, id: purchase.list0}: | ||
221 | 5 | currency_id: base.PLN | ||
222 | 6 | - | ||
223 | 7 | I create an invoice | ||
224 | 8 | - | ||
225 | 9 | !record {model: purchase.order, id: invoice1}: | ||
226 | 10 | partner_id: base.res_partner_1 | ||
227 | 11 | invoice_line_ids: | ||
228 | 12 | - product_id: product.product_product_1 | ||
229 | 13 | - product_id: product.product_product_2 | ||
230 | 14 | - | ||
231 | 15 | I confirm it | ||
232 | 16 | - | ||
233 | 17 | !workflow {model: account.invoice, action: invoice_open, ref: invoice1} | ||
234 | 18 | - | ||
235 | 19 | I check that the currency is PLN | ||
236 | 20 | - | ||
237 | 21 | !assert {model: account.invoice, id: invoice1}: | ||
238 | 22 | - currency_id.name == u'PLN' | ||
239 | 23 | - | ||
240 | 24 | I check the total | ||
241 | 25 | - | ||
242 | 26 | !assert {model: account.invoice, id: invoice1}: | ||
243 | 27 | - amount_untaxed == 188.62 | ||
244 | 28 | - | ||
245 | 29 | I check the total in alternate currencies and the rates | ||
246 | 30 | - | ||
247 | 31 | !assert {model: account.invoice, id: invoice1}: | ||
248 | 32 | - rate_eur == 0.243873 | ||
249 | 33 | - rate_usd == 0.317035 | ||
250 | 34 | - amount_untaxed_eur == 46.00 | ||
251 | 35 | - amount_untaxed_usd == 59.80 | ||
252 | 0 | 36 | ||
253 | === added file 'invoice_alternate_currency/test/set_rate.yml' | |||
254 | --- invoice_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000 | |||
255 | +++ invoice_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000 | |||
256 | @@ -0,0 +1,10 @@ | |||
257 | 1 | - | ||
258 | 2 | I set currency rates for USD because we don't know today's date | ||
259 | 3 | - | ||
260 | 4 | !record {model: res.currency.rate, id: base.rateUSD}: | ||
261 | 5 | rate: 1.3 | ||
262 | 6 | - | ||
263 | 7 | I set the same date for the second half of the year | ||
264 | 8 | - | ||
265 | 9 | !record {model: res.currency.rate, id: base.rateUSDbis}: | ||
266 | 10 | rate: 1.3 | ||
267 | 0 | 11 | ||
268 | === added directory 'invoice_alternate_currency/view' | |||
269 | === added file 'invoice_alternate_currency/view/invoice.xml' | |||
270 | --- invoice_alternate_currency/view/invoice.xml 1970-01-01 00:00:00 +0000 | |||
271 | +++ invoice_alternate_currency/view/invoice.xml 2014-07-23 10:29:51 +0000 | |||
272 | @@ -0,0 +1,81 @@ | |||
273 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
274 | 2 | <openerp> | ||
275 | 3 | <data> | ||
276 | 4 | |||
277 | 5 | <record id="invoice_supplier_form" model="ir.ui.view"> | ||
278 | 6 | <field name="name">account.invoice.form</field> | ||
279 | 7 | <field name="model">account.invoice</field> | ||
280 | 8 | <field name="inherit_id" ref="account.invoice_supplier_form"/> | ||
281 | 9 | <field | ||
282 | 10 | name="groups_id" | ||
283 | 11 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
284 | 12 | <field name="priority">4</field> | ||
285 | 13 | <field name="arch" type="xml"> | ||
286 | 14 | <notebook position="inside"> | ||
287 | 15 | <page | ||
288 | 16 | string="Other Currencies" | ||
289 | 17 | attrs="{'invisible': [('state', '==', 'draft')]}"> | ||
290 | 18 | <group> | ||
291 | 19 | <group> | ||
292 | 20 | <field name="amount_untaxed_eur"/> | ||
293 | 21 | <field name="amount_untaxed_usd"/> | ||
294 | 22 | </group> | ||
295 | 23 | <group> | ||
296 | 24 | <field name="rate_eur"/> | ||
297 | 25 | <field name="rate_usd"/> | ||
298 | 26 | </group> | ||
299 | 27 | </group> | ||
300 | 28 | </page> | ||
301 | 29 | </notebook> | ||
302 | 30 | </field> | ||
303 | 31 | </record> | ||
304 | 32 | |||
305 | 33 | <record id="invoice_form" model="ir.ui.view"> | ||
306 | 34 | <field name="name">account.invoice.form</field> | ||
307 | 35 | <field name="model">account.invoice</field> | ||
308 | 36 | <field name="inherit_id" ref="account.invoice_form"/> | ||
309 | 37 | <field | ||
310 | 38 | name="groups_id" | ||
311 | 39 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
312 | 40 | <field name="priority">4</field> | ||
313 | 41 | <field name="arch" type="xml"> | ||
314 | 42 | <notebook position="inside"> | ||
315 | 43 | <page | ||
316 | 44 | string="Other Currencies" | ||
317 | 45 | attrs="{'invisible': [('state', '==', 'draft')]}"> | ||
318 | 46 | <group> | ||
319 | 47 | <group> | ||
320 | 48 | <field name="amount_untaxed_eur"/> | ||
321 | 49 | <field name="amount_untaxed_usd"/> | ||
322 | 50 | </group> | ||
323 | 51 | <group> | ||
324 | 52 | <field name="rate_eur"/> | ||
325 | 53 | <field name="rate_usd"/> | ||
326 | 54 | </group> | ||
327 | 55 | </group> | ||
328 | 56 | </page> | ||
329 | 57 | </notebook> | ||
330 | 58 | </field> | ||
331 | 59 | </record> | ||
332 | 60 | |||
333 | 61 | <record id="invoice_tree" model="ir.ui.view"> | ||
334 | 62 | <field name="name">account.invoice.tree</field> | ||
335 | 63 | <field name="model">account.invoice</field> | ||
336 | 64 | <field name="inherit_id" ref="account.invoice_tree"/> | ||
337 | 65 | <field | ||
338 | 66 | name="groups_id" | ||
339 | 67 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
340 | 68 | <field name="arch" type="xml"> | ||
341 | 69 | <field name="amount_untaxed" position="replace"> | ||
342 | 70 | <field name="amount_untaxed" string="Untaxed"/> | ||
343 | 71 | </field> | ||
344 | 72 | <field name="amount_total" position="replace"> | ||
345 | 73 | <field name="amount_total"/> | ||
346 | 74 | <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/> | ||
347 | 75 | <field name="amount_untaxed_usd" sum="Total Untaxed USD"/> | ||
348 | 76 | </field> | ||
349 | 77 | </field> | ||
350 | 78 | </record> | ||
351 | 79 | |||
352 | 80 | </data> | ||
353 | 81 | </openerp> | ||
354 | 0 | 82 | ||
355 | === added directory 'purchase_alternate_currency' | |||
356 | === added file 'purchase_alternate_currency/__init__.py' | |||
357 | --- purchase_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000 | |||
358 | +++ purchase_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000 | |||
359 | @@ -0,0 +1,22 @@ | |||
360 | 1 | # -*- coding: utf-8 -*- | ||
361 | 2 | ############################################################################## | ||
362 | 3 | # | ||
363 | 4 | # Author: Leonardo Pistone | ||
364 | 5 | # Copyright 2014 Camptocamp SA | ||
365 | 6 | # | ||
366 | 7 | # This program is free software: you can redistribute it and/or modify | ||
367 | 8 | # it under the terms of the GNU Affero General Public License as | ||
368 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
369 | 10 | # License, or (at your option) any later version. | ||
370 | 11 | # | ||
371 | 12 | # This program is distributed in the hope that it will be useful, | ||
372 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
373 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
374 | 15 | # GNU Affero General Public License for more details. | ||
375 | 16 | # | ||
376 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
377 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
378 | 19 | # | ||
379 | 20 | ############################################################################## | ||
380 | 21 | |||
381 | 22 | from . import model # noqa | ||
382 | 0 | 23 | ||
383 | === added file 'purchase_alternate_currency/__openerp__.py' | |||
384 | --- purchase_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
385 | +++ purchase_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000 | |||
386 | @@ -0,0 +1,54 @@ | |||
387 | 1 | # -*- coding: utf-8 -*- | ||
388 | 2 | ############################################################################## | ||
389 | 3 | # | ||
390 | 4 | # Author: Leonardo Pistone | ||
391 | 5 | # Copyright 2014 Camptocamp SA | ||
392 | 6 | # | ||
393 | 7 | # This program is free software: you can redistribute it and/or modify | ||
394 | 8 | # it under the terms of the GNU Affero General Public License as | ||
395 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
396 | 10 | # License, or (at your option) any later version. | ||
397 | 11 | # | ||
398 | 12 | # This program is distributed in the hope that it will be useful, | ||
399 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
400 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
401 | 15 | # GNU Affero General Public License for more details. | ||
402 | 16 | # | ||
403 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
404 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
405 | 19 | # | ||
406 | 20 | ############################################################################## | ||
407 | 21 | { | ||
408 | 22 | 'name': 'Purchase Alternate Currency', | ||
409 | 23 | 'version': '1.0', | ||
410 | 24 | 'category': 'Generic Modules/Purchase', | ||
411 | 25 | 'description': """ | ||
412 | 26 | Purchase Alternate Currency | ||
413 | 27 | =========================== | ||
414 | 28 | |||
415 | 29 | This module shows the value untaxed total of the purchase order in two, fixed | ||
416 | 30 | alternate currencies. These two currencies are hardcoded. | ||
417 | 31 | |||
418 | 32 | The totals are written at the moment when the order is confirmed. The rate | ||
419 | 33 | used is stored, too. | ||
420 | 34 | |||
421 | 35 | Contributors | ||
422 | 36 | ------------ | ||
423 | 37 | |||
424 | 38 | * Leonardo Pistone <leonardo.pistone@camptocamp.com> | ||
425 | 39 | |||
426 | 40 | """, | ||
427 | 41 | 'author': 'Camptocamp', | ||
428 | 42 | 'depends': ['purchase'], | ||
429 | 43 | 'website': 'http://www.camptocamp.com', | ||
430 | 44 | 'data': [ | ||
431 | 45 | 'view/purchase.xml', | ||
432 | 46 | ], | ||
433 | 47 | 'test': [ | ||
434 | 48 | 'test/set_rate.yml', | ||
435 | 49 | 'test/purchase_alternate_currency.yml', | ||
436 | 50 | ], | ||
437 | 51 | 'demo': [], | ||
438 | 52 | 'installable': True, | ||
439 | 53 | 'active': False, | ||
440 | 54 | } | ||
441 | 0 | 55 | ||
442 | === added directory 'purchase_alternate_currency/model' | |||
443 | === added file 'purchase_alternate_currency/model/__init__.py' | |||
444 | --- purchase_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
445 | +++ purchase_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000 | |||
446 | @@ -0,0 +1,22 @@ | |||
447 | 1 | # -*- coding: utf-8 -*- | ||
448 | 2 | ############################################################################## | ||
449 | 3 | # | ||
450 | 4 | # Author: Leonardo Pistone | ||
451 | 5 | # Copyright 2014 Camptocamp SA | ||
452 | 6 | # | ||
453 | 7 | # This program is free software: you can redistribute it and/or modify | ||
454 | 8 | # it under the terms of the GNU Affero General Public License as | ||
455 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
456 | 10 | # License, or (at your option) any later version. | ||
457 | 11 | # | ||
458 | 12 | # This program is distributed in the hope that it will be useful, | ||
459 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
460 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
461 | 15 | # GNU Affero General Public License for more details. | ||
462 | 16 | # | ||
463 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
464 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
465 | 19 | # | ||
466 | 20 | ############################################################################## | ||
467 | 21 | |||
468 | 22 | from . import purchase # noqa | ||
469 | 0 | 23 | ||
470 | === added file 'purchase_alternate_currency/model/purchase.py' | |||
471 | --- purchase_alternate_currency/model/purchase.py 1970-01-01 00:00:00 +0000 | |||
472 | +++ purchase_alternate_currency/model/purchase.py 2014-07-23 10:29:51 +0000 | |||
473 | @@ -0,0 +1,90 @@ | |||
474 | 1 | # -*- coding: utf-8 -*- | ||
475 | 2 | ############################################################################## | ||
476 | 3 | # | ||
477 | 4 | # Author: Leonardo Pistone | ||
478 | 5 | # Copyright 2014 Camptocamp SA | ||
479 | 6 | # | ||
480 | 7 | # This program is free software: you can redistribute it and/or modify | ||
481 | 8 | # it under the terms of the GNU Affero General Public License as | ||
482 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
483 | 10 | # License, or (at your option) any later version. | ||
484 | 11 | # | ||
485 | 12 | # This program is distributed in the hope that it will be useful, | ||
486 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
487 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
488 | 15 | # GNU Affero General Public License for more details. | ||
489 | 16 | # | ||
490 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
491 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
492 | 19 | # | ||
493 | 20 | ############################################################################## | ||
494 | 21 | |||
495 | 22 | from openerp.osv import orm, fields | ||
496 | 23 | import openerp.addons.decimal_precision as dp | ||
497 | 24 | |||
498 | 25 | |||
499 | 26 | class PurchaseOrder(orm.Model): | ||
500 | 27 | _inherit = 'purchase.order' | ||
501 | 28 | |||
502 | 29 | _columns = { | ||
503 | 30 | 'rate_eur': fields.float( | ||
504 | 31 | 'EUR Rate when confirmed', digits=(12, 6), | ||
505 | 32 | readonly=True, | ||
506 | 33 | help='The rate used when the order was confirmed'), | ||
507 | 34 | 'rate_usd': fields.float( | ||
508 | 35 | 'USD Rate when confirmed', digits=(12, 6), | ||
509 | 36 | readonly=True, | ||
510 | 37 | help='The rate used when the order was confirmed'), | ||
511 | 38 | 'amount_untaxed_eur': fields.float( | ||
512 | 39 | 'EUR Untaxed', | ||
513 | 40 | digits_compute=dp.get_precision('Account'), | ||
514 | 41 | readonly=True, | ||
515 | 42 | help='Untaxed Amount in EUR ' | ||
516 | 43 | 'computed at when the order is confirmed', | ||
517 | 44 | ), | ||
518 | 45 | 'amount_untaxed_usd': fields.float( | ||
519 | 46 | 'USD Untaxed', | ||
520 | 47 | digits_compute=dp.get_precision('Account'), | ||
521 | 48 | readonly=True, | ||
522 | 49 | help='Untaxed Amount in USD ' | ||
523 | 50 | 'computed at when the order is confirmed', | ||
524 | 51 | ), | ||
525 | 52 | } | ||
526 | 53 | |||
527 | 54 | def wkf_confirm_order(self, cr, uid, ids, context=None): | ||
528 | 55 | super(PurchaseOrder, self).wkf_confirm_order(cr, uid, ids, context) | ||
529 | 56 | |||
530 | 57 | currency_obj = self.pool['res.currency'] | ||
531 | 58 | mod_obj = self.pool['ir.model.data'] | ||
532 | 59 | eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1] | ||
533 | 60 | usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1] | ||
534 | 61 | eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id], | ||
535 | 62 | context=context) | ||
536 | 63 | |||
537 | 64 | for order in self.browse(cr, uid, ids, context=context): | ||
538 | 65 | order.write({ | ||
539 | 66 | 'rate_eur': currency_obj._get_conversion_rate( | ||
540 | 67 | cr, uid, order.currency_id, eur, context=context), | ||
541 | 68 | 'rate_usd': currency_obj._get_conversion_rate( | ||
542 | 69 | cr, uid, order.currency_id, usd, context=context), | ||
543 | 70 | 'amount_untaxed_eur': currency_obj.compute( | ||
544 | 71 | cr, uid, order.currency_id.id, eur_id, | ||
545 | 72 | order.amount_untaxed, context=context), | ||
546 | 73 | 'amount_untaxed_usd': currency_obj.compute( | ||
547 | 74 | cr, uid, order.currency_id.id, usd_id, | ||
548 | 75 | order.amount_untaxed, context=context), | ||
549 | 76 | }) | ||
550 | 77 | |||
551 | 78 | return True | ||
552 | 79 | |||
553 | 80 | def copy_data(self, cr, uid, id, default, context): | ||
554 | 81 | if default is None: | ||
555 | 82 | default = {} | ||
556 | 83 | |||
557 | 84 | default.update({ | ||
558 | 85 | field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur', | ||
559 | 86 | 'rate_usd', 'amount_untaxed_usd') | ||
560 | 87 | }) | ||
561 | 88 | |||
562 | 89 | return super(PurchaseOrder, self).copy_data(cr, uid, id, default, | ||
563 | 90 | context) | ||
564 | 0 | 91 | ||
565 | === added directory 'purchase_alternate_currency/test' | |||
566 | === added file 'purchase_alternate_currency/test/purchase_alternate_currency.yml' | |||
567 | --- purchase_alternate_currency/test/purchase_alternate_currency.yml 1970-01-01 00:00:00 +0000 | |||
568 | +++ purchase_alternate_currency/test/purchase_alternate_currency.yml 2014-07-23 10:29:51 +0000 | |||
569 | @@ -0,0 +1,35 @@ | |||
570 | 1 | - | ||
571 | 2 | I change the currency of the default pricelist to PLN | ||
572 | 3 | - | ||
573 | 4 | !record {model: product.pricelist, id: purchase.list0}: | ||
574 | 5 | currency_id: base.PLN | ||
575 | 6 | - | ||
576 | 7 | I create a purchase order | ||
577 | 8 | - | ||
578 | 9 | !record {model: purchase.order, id: order1}: | ||
579 | 10 | partner_id: base.res_partner_1 | ||
580 | 11 | order_line: | ||
581 | 12 | - product_id: product.product_product_1 | ||
582 | 13 | - product_id: product.product_product_2 | ||
583 | 14 | - | ||
584 | 15 | I confirm it | ||
585 | 16 | - | ||
586 | 17 | !workflow {model: purchase.order, action: purchase_confirm, ref: order1} | ||
587 | 18 | - | ||
588 | 19 | I check that the currency is PLN | ||
589 | 20 | - | ||
590 | 21 | !assert {model: purchase.order, id: order1}: | ||
591 | 22 | - currency_id.name == u'PLN' | ||
592 | 23 | - | ||
593 | 24 | I check the total | ||
594 | 25 | - | ||
595 | 26 | !assert {model: purchase.order, id: order1}: | ||
596 | 27 | - amount_untaxed == 188.62 | ||
597 | 28 | - | ||
598 | 29 | I check the total in alternate currencies and the rates | ||
599 | 30 | - | ||
600 | 31 | !assert {model: purchase.order, id: order1}: | ||
601 | 32 | - rate_eur == 0.243873 | ||
602 | 33 | - rate_usd == 0.317035 | ||
603 | 34 | - amount_untaxed_eur == 46.00 | ||
604 | 35 | - amount_untaxed_usd == 59.80 | ||
605 | 0 | 36 | ||
606 | === added file 'purchase_alternate_currency/test/set_rate.yml' | |||
607 | --- purchase_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000 | |||
608 | +++ purchase_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000 | |||
609 | @@ -0,0 +1,10 @@ | |||
610 | 1 | - | ||
611 | 2 | I set currency rates for USD because we don't know today's date | ||
612 | 3 | - | ||
613 | 4 | !record {model: res.currency.rate, id: base.rateUSD}: | ||
614 | 5 | rate: 1.3 | ||
615 | 6 | - | ||
616 | 7 | I set the same date for the second half of the year | ||
617 | 8 | - | ||
618 | 9 | !record {model: res.currency.rate, id: base.rateUSDbis}: | ||
619 | 10 | rate: 1.3 | ||
620 | 0 | 11 | ||
621 | === added directory 'purchase_alternate_currency/view' | |||
622 | === added file 'purchase_alternate_currency/view/purchase.xml' | |||
623 | --- purchase_alternate_currency/view/purchase.xml 1970-01-01 00:00:00 +0000 | |||
624 | +++ purchase_alternate_currency/view/purchase.xml 2014-07-23 10:29:51 +0000 | |||
625 | @@ -0,0 +1,54 @@ | |||
626 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
627 | 2 | <openerp> | ||
628 | 3 | <data> | ||
629 | 4 | |||
630 | 5 | <record id="purchase_order_form" model="ir.ui.view"> | ||
631 | 6 | <field name="name">purchase.order.form</field> | ||
632 | 7 | <field name="model">purchase.order</field> | ||
633 | 8 | <field name="inherit_id" ref="purchase.purchase_order_form"/> | ||
634 | 9 | <field | ||
635 | 10 | name="groups_id" | ||
636 | 11 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
637 | 12 | <field name="arch" type="xml"> | ||
638 | 13 | |||
639 | 14 | <notebook position="inside"> | ||
640 | 15 | <page | ||
641 | 16 | string="Other Currencies" | ||
642 | 17 | attrs="{'invisible': [('state','in', ('draft', 'sent'))]}"> | ||
643 | 18 | <group> | ||
644 | 19 | <group> | ||
645 | 20 | <field name="amount_untaxed_eur"/> | ||
646 | 21 | <field name="amount_untaxed_usd"/> | ||
647 | 22 | </group> | ||
648 | 23 | <group> | ||
649 | 24 | <field name="rate_eur"/> | ||
650 | 25 | <field name="rate_usd"/> | ||
651 | 26 | </group> | ||
652 | 27 | </group> | ||
653 | 28 | </page> | ||
654 | 29 | </notebook> | ||
655 | 30 | </field> | ||
656 | 31 | </record> | ||
657 | 32 | |||
658 | 33 | <record id="purchase_order_tree" model="ir.ui.view"> | ||
659 | 34 | <field name="name">purchase.order.tree</field> | ||
660 | 35 | <field name="model">purchase.order</field> | ||
661 | 36 | <field name="inherit_id" ref="purchase.purchase_order_tree"/> | ||
662 | 37 | <field | ||
663 | 38 | name="groups_id" | ||
664 | 39 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
665 | 40 | <field name="arch" type="xml"> | ||
666 | 41 | <field name="amount_untaxed" position="replace"> | ||
667 | 42 | <field name="currency_id" string="Currency"/> | ||
668 | 43 | <field name="amount_untaxed" string="Untaxed"/> | ||
669 | 44 | </field> | ||
670 | 45 | <field name="amount_total" position="replace"> | ||
671 | 46 | <field name="amount_total"/> | ||
672 | 47 | <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/> | ||
673 | 48 | <field name="amount_untaxed_usd" sum="Total Untaxed USD"/> | ||
674 | 49 | </field> | ||
675 | 50 | </field> | ||
676 | 51 | </record> | ||
677 | 52 | |||
678 | 53 | </data> | ||
679 | 54 | </openerp> | ||
680 | 0 | 55 | ||
681 | === added directory 'sale_alternate_currency' | |||
682 | === added file 'sale_alternate_currency/__init__.py' | |||
683 | --- sale_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000 | |||
684 | +++ sale_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000 | |||
685 | @@ -0,0 +1,22 @@ | |||
686 | 1 | # -*- coding: utf-8 -*- | ||
687 | 2 | ############################################################################## | ||
688 | 3 | # | ||
689 | 4 | # Author: Leonardo Pistone | ||
690 | 5 | # Copyright 2014 Camptocamp SA | ||
691 | 6 | # | ||
692 | 7 | # This program is free software: you can redistribute it and/or modify | ||
693 | 8 | # it under the terms of the GNU Affero General Public License as | ||
694 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
695 | 10 | # License, or (at your option) any later version. | ||
696 | 11 | # | ||
697 | 12 | # This program is distributed in the hope that it will be useful, | ||
698 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
699 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
700 | 15 | # GNU Affero General Public License for more details. | ||
701 | 16 | # | ||
702 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
703 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
704 | 19 | # | ||
705 | 20 | ############################################################################## | ||
706 | 21 | |||
707 | 22 | from . import model # noqa | ||
708 | 0 | 23 | ||
709 | === added file 'sale_alternate_currency/__openerp__.py' | |||
710 | --- sale_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
711 | +++ sale_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000 | |||
712 | @@ -0,0 +1,54 @@ | |||
713 | 1 | # -*- coding: utf-8 -*- | ||
714 | 2 | ############################################################################## | ||
715 | 3 | # | ||
716 | 4 | # Author: Leonardo Pistone | ||
717 | 5 | # Copyright 2014 Camptocamp SA | ||
718 | 6 | # | ||
719 | 7 | # This program is free software: you can redistribute it and/or modify | ||
720 | 8 | # it under the terms of the GNU Affero General Public License as | ||
721 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
722 | 10 | # License, or (at your option) any later version. | ||
723 | 11 | # | ||
724 | 12 | # This program is distributed in the hope that it will be useful, | ||
725 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
726 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
727 | 15 | # GNU Affero General Public License for more details. | ||
728 | 16 | # | ||
729 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
730 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
731 | 19 | # | ||
732 | 20 | ############################################################################## | ||
733 | 21 | { | ||
734 | 22 | 'name': 'Sale Alternate Currency', | ||
735 | 23 | 'version': '1.0', | ||
736 | 24 | 'category': 'Generic Modules/Sale', | ||
737 | 25 | 'description': """ | ||
738 | 26 | Sale Alternate Currency | ||
739 | 27 | ======================= | ||
740 | 28 | |||
741 | 29 | This module shows the value untaxed total of the sale order in two, fixed | ||
742 | 30 | alternate currencies. These two currencies are hardcoded. | ||
743 | 31 | |||
744 | 32 | The totals are written at the moment when the order is confirmed. The rate | ||
745 | 33 | used is stored, too. | ||
746 | 34 | |||
747 | 35 | Contributors | ||
748 | 36 | ------------ | ||
749 | 37 | |||
750 | 38 | * Leonardo Pistone <leonardo.pistone@camptocamp.com> | ||
751 | 39 | |||
752 | 40 | """, | ||
753 | 41 | 'author': 'Camptocamp', | ||
754 | 42 | 'depends': ['sale'], | ||
755 | 43 | 'website': 'http://www.camptocamp.com', | ||
756 | 44 | 'data': [ | ||
757 | 45 | 'view/sale.xml', | ||
758 | 46 | ], | ||
759 | 47 | 'test': [ | ||
760 | 48 | 'test/set_rate.yml', | ||
761 | 49 | 'test/sale_alternate_currency.yml', | ||
762 | 50 | ], | ||
763 | 51 | 'demo': [], | ||
764 | 52 | 'installable': True, | ||
765 | 53 | 'active': False, | ||
766 | 54 | } | ||
767 | 0 | 55 | ||
768 | === added directory 'sale_alternate_currency/model' | |||
769 | === added file 'sale_alternate_currency/model/__init__.py' | |||
770 | --- sale_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
771 | +++ sale_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000 | |||
772 | @@ -0,0 +1,22 @@ | |||
773 | 1 | # -*- coding: utf-8 -*- | ||
774 | 2 | ############################################################################## | ||
775 | 3 | # | ||
776 | 4 | # Author: Leonardo Pistone | ||
777 | 5 | # Copyright 2014 Camptocamp SA | ||
778 | 6 | # | ||
779 | 7 | # This program is free software: you can redistribute it and/or modify | ||
780 | 8 | # it under the terms of the GNU Affero General Public License as | ||
781 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
782 | 10 | # License, or (at your option) any later version. | ||
783 | 11 | # | ||
784 | 12 | # This program is distributed in the hope that it will be useful, | ||
785 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
786 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
787 | 15 | # GNU Affero General Public License for more details. | ||
788 | 16 | # | ||
789 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
790 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
791 | 19 | # | ||
792 | 20 | ############################################################################## | ||
793 | 21 | |||
794 | 22 | from . import sale # noqa | ||
795 | 0 | 23 | ||
796 | === added file 'sale_alternate_currency/model/sale.py' | |||
797 | --- sale_alternate_currency/model/sale.py 1970-01-01 00:00:00 +0000 | |||
798 | +++ sale_alternate_currency/model/sale.py 2014-07-23 10:29:51 +0000 | |||
799 | @@ -0,0 +1,89 @@ | |||
800 | 1 | # -*- coding: utf-8 -*- | ||
801 | 2 | ############################################################################## | ||
802 | 3 | # | ||
803 | 4 | # Author: Leonardo Pistone | ||
804 | 5 | # Copyright 2014 Camptocamp SA | ||
805 | 6 | # | ||
806 | 7 | # This program is free software: you can redistribute it and/or modify | ||
807 | 8 | # it under the terms of the GNU Affero General Public License as | ||
808 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
809 | 10 | # License, or (at your option) any later version. | ||
810 | 11 | # | ||
811 | 12 | # This program is distributed in the hope that it will be useful, | ||
812 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
813 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
814 | 15 | # GNU Affero General Public License for more details. | ||
815 | 16 | # | ||
816 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
817 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
818 | 19 | # | ||
819 | 20 | ############################################################################## | ||
820 | 21 | |||
821 | 22 | from openerp.osv import orm, fields | ||
822 | 23 | import openerp.addons.decimal_precision as dp | ||
823 | 24 | |||
824 | 25 | |||
825 | 26 | class SaleOrder(orm.Model): | ||
826 | 27 | _inherit = 'sale.order' | ||
827 | 28 | |||
828 | 29 | _columns = { | ||
829 | 30 | 'rate_eur': fields.float( | ||
830 | 31 | 'EUR Rate when confirmed', digits=(12, 6), | ||
831 | 32 | readonly=True, | ||
832 | 33 | help='The rate used when the order was confirmed'), | ||
833 | 34 | 'rate_usd': fields.float( | ||
834 | 35 | 'USD Rate when confirmed', digits=(12, 6), | ||
835 | 36 | readonly=True, | ||
836 | 37 | help='The rate used when the order was confirmed'), | ||
837 | 38 | 'amount_untaxed_eur': fields.float( | ||
838 | 39 | 'EUR Untaxed', | ||
839 | 40 | digits_compute=dp.get_precision('Account'), | ||
840 | 41 | readonly=True, | ||
841 | 42 | help='Untaxed Amount in EUR ' | ||
842 | 43 | 'computed at when the order is confirmed', | ||
843 | 44 | ), | ||
844 | 45 | 'amount_untaxed_usd': fields.float( | ||
845 | 46 | 'USD Untaxed', | ||
846 | 47 | digits_compute=dp.get_precision('Account'), | ||
847 | 48 | readonly=True, | ||
848 | 49 | help='Untaxed Amount in USD ' | ||
849 | 50 | 'computed at when the order is confirmed', | ||
850 | 51 | ), | ||
851 | 52 | } | ||
852 | 53 | |||
853 | 54 | def action_wait(self, cr, uid, ids, context=None): | ||
854 | 55 | super(SaleOrder, self).action_wait(cr, uid, ids, context) | ||
855 | 56 | |||
856 | 57 | currency_obj = self.pool['res.currency'] | ||
857 | 58 | mod_obj = self.pool['ir.model.data'] | ||
858 | 59 | eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1] | ||
859 | 60 | usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1] | ||
860 | 61 | eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id], | ||
861 | 62 | context=context) | ||
862 | 63 | |||
863 | 64 | for order in self.browse(cr, uid, ids, context=context): | ||
864 | 65 | order.write({ | ||
865 | 66 | 'rate_eur': currency_obj._get_conversion_rate( | ||
866 | 67 | cr, uid, order.currency_id, eur, context=context), | ||
867 | 68 | 'rate_usd': currency_obj._get_conversion_rate( | ||
868 | 69 | cr, uid, order.currency_id, usd, context=context), | ||
869 | 70 | 'amount_untaxed_eur': currency_obj.compute( | ||
870 | 71 | cr, uid, order.currency_id.id, eur_id, | ||
871 | 72 | order.amount_untaxed, context=context), | ||
872 | 73 | 'amount_untaxed_usd': currency_obj.compute( | ||
873 | 74 | cr, uid, order.currency_id.id, usd_id, | ||
874 | 75 | order.amount_untaxed, context=context), | ||
875 | 76 | }) | ||
876 | 77 | |||
877 | 78 | return True | ||
878 | 79 | |||
879 | 80 | def copy_data(self, cr, uid, id, default, context): | ||
880 | 81 | if default is None: | ||
881 | 82 | default = {} | ||
882 | 83 | |||
883 | 84 | default.update({ | ||
884 | 85 | field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur', | ||
885 | 86 | 'rate_usd', 'amount_untaxed_usd') | ||
886 | 87 | }) | ||
887 | 88 | |||
888 | 89 | return super(SaleOrder, self).copy_data(cr, uid, id, default, context) | ||
889 | 0 | 90 | ||
890 | === added directory 'sale_alternate_currency/test' | |||
891 | === added file 'sale_alternate_currency/test/sale_alternate_currency.yml' | |||
892 | --- sale_alternate_currency/test/sale_alternate_currency.yml 1970-01-01 00:00:00 +0000 | |||
893 | +++ sale_alternate_currency/test/sale_alternate_currency.yml 2014-07-23 10:29:51 +0000 | |||
894 | @@ -0,0 +1,36 @@ | |||
895 | 1 | - | ||
896 | 2 | I change the currency of the default pricelist to PLN | ||
897 | 3 | - | ||
898 | 4 | !record {model: product.pricelist, id: product.list0}: | ||
899 | 5 | currency_id: base.PLN | ||
900 | 6 | - | ||
901 | 7 | I create a sale order | ||
902 | 8 | - | ||
903 | 9 | !record {model: sale.order, id: order1}: | ||
904 | 10 | partner_id: base.res_partner_1 | ||
905 | 11 | order_line: | ||
906 | 12 | - product_id: product.product_product_1 | ||
907 | 13 | product_uom_qty: 5 | ||
908 | 14 | - product_id: product.product_product_2 | ||
909 | 15 | - | ||
910 | 16 | I confirm it | ||
911 | 17 | - | ||
912 | 18 | !workflow {model: sale.order, action: order_confirm, ref: order1} | ||
913 | 19 | - | ||
914 | 20 | I check that the currency is PLN | ||
915 | 21 | - | ||
916 | 22 | !assert {model: sale.order, id: order1}: | ||
917 | 23 | - currency_id.name == u'PLN' | ||
918 | 24 | - | ||
919 | 25 | I check the total | ||
920 | 26 | - | ||
921 | 27 | !assert {model: sale.order, id: order1}: | ||
922 | 28 | - amount_untaxed == 787.29 | ||
923 | 29 | - | ||
924 | 30 | I check the total in alternate currencies and the rates | ||
925 | 31 | - | ||
926 | 32 | !assert {model: sale.order, id: order1}: | ||
927 | 33 | - rate_eur == 0.243873 | ||
928 | 34 | - rate_usd == 0.317035 | ||
929 | 35 | - amount_untaxed_eur == 192.00 | ||
930 | 36 | - amount_untaxed_usd == 249.60 | ||
931 | 0 | 37 | ||
932 | === added file 'sale_alternate_currency/test/set_rate.yml' | |||
933 | --- sale_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000 | |||
934 | +++ sale_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000 | |||
935 | @@ -0,0 +1,10 @@ | |||
936 | 1 | - | ||
937 | 2 | I set currency rates for USD because we don't know today's date | ||
938 | 3 | - | ||
939 | 4 | !record {model: res.currency.rate, id: base.rateUSD}: | ||
940 | 5 | rate: 1.3 | ||
941 | 6 | - | ||
942 | 7 | I set the same date for the second half of the year | ||
943 | 8 | - | ||
944 | 9 | !record {model: res.currency.rate, id: base.rateUSDbis}: | ||
945 | 10 | rate: 1.3 | ||
946 | 0 | 11 | ||
947 | === added directory 'sale_alternate_currency/view' | |||
948 | === added file 'sale_alternate_currency/view/sale.xml' | |||
949 | --- sale_alternate_currency/view/sale.xml 1970-01-01 00:00:00 +0000 | |||
950 | +++ sale_alternate_currency/view/sale.xml 2014-07-23 10:29:51 +0000 | |||
951 | @@ -0,0 +1,68 @@ | |||
952 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
953 | 2 | <openerp> | ||
954 | 3 | <data> | ||
955 | 4 | |||
956 | 5 | <record id="view_order_form" model="ir.ui.view"> | ||
957 | 6 | <field name="name">sale.order.form</field> | ||
958 | 7 | <field name="model">sale.order</field> | ||
959 | 8 | <field name="inherit_id" ref="sale.view_order_form"/> | ||
960 | 9 | <field | ||
961 | 10 | name="groups_id" | ||
962 | 11 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
963 | 12 | <field name="arch" type="xml"> | ||
964 | 13 | |||
965 | 14 | <notebook position="inside"> | ||
966 | 15 | <page string="Other Currencies" | ||
967 | 16 | attrs="{'invisible': [('state','in', ('draft', 'sent'))]}"> | ||
968 | 17 | <group> | ||
969 | 18 | <group> | ||
970 | 19 | <field name="amount_untaxed_eur"/> | ||
971 | 20 | <field name="amount_untaxed_usd"/> | ||
972 | 21 | </group> | ||
973 | 22 | <group> | ||
974 | 23 | <field name="rate_eur"/> | ||
975 | 24 | <field name="rate_usd"/> | ||
976 | 25 | </group> | ||
977 | 26 | </group> | ||
978 | 27 | </page> | ||
979 | 28 | </notebook> | ||
980 | 29 | </field> | ||
981 | 30 | </record> | ||
982 | 31 | |||
983 | 32 | <record id="view_order_tree" model="ir.ui.view"> | ||
984 | 33 | <field name="name">sale.order.tree</field> | ||
985 | 34 | <field name="model">sale.order</field> | ||
986 | 35 | <field name="inherit_id" ref="sale.view_order_tree"/> | ||
987 | 36 | <field | ||
988 | 37 | name="groups_id" | ||
989 | 38 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
990 | 39 | <field name="arch" type="xml"> | ||
991 | 40 | <field name="amount_total" position="replace"> | ||
992 | 41 | <field name="currency_id" string="Currency"/> | ||
993 | 42 | <field name="amount_total"/> | ||
994 | 43 | <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/> | ||
995 | 44 | <field name="amount_untaxed_usd" sum="Total Untaxed USD"/> | ||
996 | 45 | </field> | ||
997 | 46 | </field> | ||
998 | 47 | </record> | ||
999 | 48 | |||
1000 | 49 | <record id="view_quotation_tree" model="ir.ui.view"> | ||
1001 | 50 | <field name="name">sale.order.tree</field> | ||
1002 | 51 | <field name="model">sale.order</field> | ||
1003 | 52 | <field name="inherit_id" ref="sale.view_quotation_tree"/> | ||
1004 | 53 | <field | ||
1005 | 54 | name="groups_id" | ||
1006 | 55 | eval="[(6, 0, [ref('base.group_multi_currency')])]"/> | ||
1007 | 56 | <field name="arch" type="xml"> | ||
1008 | 57 | <field name="amount_total" position="replace"> | ||
1009 | 58 | <field name="currency_id" string="Currency"/> | ||
1010 | 59 | <field name="amount_total"/> | ||
1011 | 60 | <field name="amount_untaxed" string="Untaxed"/> | ||
1012 | 61 | <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/> | ||
1013 | 62 | <field name="amount_untaxed_usd" sum="Total Untaxed USD"/> | ||
1014 | 63 | </field> | ||
1015 | 64 | </field> | ||
1016 | 65 | </record> | ||
1017 | 66 | |||
1018 | 67 | </data> | ||
1019 | 68 | </openerp> |
Thanks for continuing on that, Matthieu.
In the new "invoice_ alternate_ currency" There are some mentions to "purchase" like line 58 of the diff. Can you fix those please?