Merge lp:~camptocamp/c2c-addons/add-alternate-currency-lep into lp:c2c-addons

Proposed by Leonardo Pistone on 2014-07-18
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
Reviewer Review Type Date Requested Status
Leonardo Pistone Needs Fixing on 2014-08-05
Review via email: mp+227373@code.launchpad.net

Description of the change

2 new modules: sale_alternate_currency and purchase_alternate_currency.

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 on 2014-07-23

[ADD] added invoice untaxed totals + corrected a few columns

Leonardo Pistone (lepistone) wrote :

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?

review: Needs Fixing
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 on 2014-07-23

[ADD] added invoice untaxed totals + corrected a few columns

14. By Leonardo Pistone on 2014-07-18

sale_alternate_currency: don'y show in draft

13. By Leonardo Pistone on 2014-07-18

purchase_alternate_currency: don't show in draft

12. By Leonardo Pistone on 2014-07-18

add purchase_alternate_currency

11. By Leonardo Pistone on 2014-07-18

add totals to tree view, change labels

10. By Leonardo Pistone on 2014-07-18

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

Subscribers

People subscribed via source and target branches

to all changes: