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

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
Reviewer Review Type Date Requested Status
Leonardo Pistone Needs Fixing
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

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

Revision history for this message
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
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
=== added directory 'invoice_alternate_currency'
=== added file 'invoice_alternate_currency/__init__.py'
--- invoice_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Matthieu Dietrich
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import model # noqa
023
=== added file 'invoice_alternate_currency/__openerp__.py'
--- invoice_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,55 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Matthieu Dietrich
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 'name': 'Invoice Alternate Currency',
23 'version': '1.0',
24 'category': 'Generic Modules/Purchase',
25 'description': """
26Purchase Alternate Currency
27===========================
28
29This module shows the value untaxed total of the invoice in two, fixed
30alternate currencies. These two currencies are hardcoded.
31
32The totals are written at the moment when the invoice is confirmed. The rate
33used is stored, too.
34
35Contributors
36------------
37
38 * Leonardo Pistone <leonardo.pistone@camptocamp.com>
39 * Matthieu Dietrich <matthieu.dietrich@camptocamp.com>
40
41""",
42 'author': 'Camptocamp',
43 'depends': ['account'],
44 'website': 'http://www.camptocamp.com',
45 'data': [
46 'view/invoice.xml',
47 ],
48 'test': [
49 'test/set_rate.yml',
50 'test/invoice_alternate_currency.yml',
51 ],
52 'demo': [],
53 'installable': True,
54 'active': False,
55}
056
=== added directory 'invoice_alternate_currency/model'
=== added file 'invoice_alternate_currency/model/__init__.py'
--- invoice_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Matthieu Dietrich
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import invoice # noqa
023
=== added file 'invoice_alternate_currency/model/invoice.py'
--- invoice_alternate_currency/model/invoice.py 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/model/invoice.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,90 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Matthieu Dietrich
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import openerp.addons.decimal_precision as dp
24
25
26class AccountInvoice(orm.Model):
27 _inherit = 'account.invoice'
28
29 _columns = {
30 'rate_eur': fields.float(
31 'EUR Rate when confirmed', digits=(12, 6),
32 readonly=True,
33 help='The rate used when the order was confirmed'),
34 'rate_usd': fields.float(
35 'USD Rate when confirmed', digits=(12, 6),
36 readonly=True,
37 help='The rate used when the order was confirmed'),
38 'amount_untaxed_eur': fields.float(
39 'EUR Untaxed',
40 digits_compute=dp.get_precision('Account'),
41 readonly=True,
42 help='Untaxed Amount in EUR '
43 'computed at when the order is confirmed',
44 ),
45 'amount_untaxed_usd': fields.float(
46 'USD Untaxed',
47 digits_compute=dp.get_precision('Account'),
48 readonly=True,
49 help='Untaxed Amount in USD '
50 'computed at when the order is confirmed',
51 ),
52 }
53
54 def invoice_validate(self, cr, uid, ids, context=None):
55 super(AccountInvoice, self).invoice_validate(cr, uid, ids, context)
56
57 currency_obj = self.pool['res.currency']
58 mod_obj = self.pool['ir.model.data']
59 eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1]
60 usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1]
61 eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id],
62 context=context)
63
64 for invoice in self.browse(cr, uid, ids, context=context):
65 invoice.write({
66 'rate_eur': currency_obj._get_conversion_rate(
67 cr, uid, invoice.currency_id, eur, context=context),
68 'rate_usd': currency_obj._get_conversion_rate(
69 cr, uid, invoice.currency_id, usd, context=context),
70 'amount_untaxed_eur': currency_obj.compute(
71 cr, uid, invoice.currency_id.id, eur_id,
72 invoice.amount_untaxed, context=context),
73 'amount_untaxed_usd': currency_obj.compute(
74 cr, uid, invoice.currency_id.id, usd_id,
75 invoice.amount_untaxed, context=context),
76 })
77
78 return True
79
80 def copy_data(self, cr, uid, id, default, context):
81 if default is None:
82 default = {}
83
84 default.update({
85 field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur',
86 'rate_usd', 'amount_untaxed_usd')
87 })
88
89 return super(AccountInvoice, self).copy_data(cr, uid, id, default,
90 context)
091
=== added directory 'invoice_alternate_currency/test'
=== added file 'invoice_alternate_currency/test/invoice_alternate_currency.yml'
--- invoice_alternate_currency/test/invoice_alternate_currency.yml 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/test/invoice_alternate_currency.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,35 @@
1-
2 I change the currency of the default pricelist to PLN
3-
4 !record {model: product.pricelist, id: purchase.list0}:
5 currency_id: base.PLN
6-
7 I create an invoice
8-
9 !record {model: purchase.order, id: invoice1}:
10 partner_id: base.res_partner_1
11 invoice_line_ids:
12 - product_id: product.product_product_1
13 - product_id: product.product_product_2
14-
15 I confirm it
16-
17 !workflow {model: account.invoice, action: invoice_open, ref: invoice1}
18-
19 I check that the currency is PLN
20-
21 !assert {model: account.invoice, id: invoice1}:
22 - currency_id.name == u'PLN'
23-
24 I check the total
25-
26 !assert {model: account.invoice, id: invoice1}:
27 - amount_untaxed == 188.62
28-
29 I check the total in alternate currencies and the rates
30-
31 !assert {model: account.invoice, id: invoice1}:
32 - rate_eur == 0.243873
33 - rate_usd == 0.317035
34 - amount_untaxed_eur == 46.00
35 - amount_untaxed_usd == 59.80
036
=== added file 'invoice_alternate_currency/test/set_rate.yml'
--- invoice_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,10 @@
1-
2 I set currency rates for USD because we don't know today's date
3-
4 !record {model: res.currency.rate, id: base.rateUSD}:
5 rate: 1.3
6-
7 I set the same date for the second half of the year
8-
9 !record {model: res.currency.rate, id: base.rateUSDbis}:
10 rate: 1.3
011
=== added directory 'invoice_alternate_currency/view'
=== added file 'invoice_alternate_currency/view/invoice.xml'
--- invoice_alternate_currency/view/invoice.xml 1970-01-01 00:00:00 +0000
+++ invoice_alternate_currency/view/invoice.xml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,81 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="invoice_supplier_form" model="ir.ui.view">
6 <field name="name">account.invoice.form</field>
7 <field name="model">account.invoice</field>
8 <field name="inherit_id" ref="account.invoice_supplier_form"/>
9 <field
10 name="groups_id"
11 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
12 <field name="priority">4</field>
13 <field name="arch" type="xml">
14 <notebook position="inside">
15 <page
16 string="Other Currencies"
17 attrs="{'invisible': [('state', '==', 'draft')]}">
18 <group>
19 <group>
20 <field name="amount_untaxed_eur"/>
21 <field name="amount_untaxed_usd"/>
22 </group>
23 <group>
24 <field name="rate_eur"/>
25 <field name="rate_usd"/>
26 </group>
27 </group>
28 </page>
29 </notebook>
30 </field>
31 </record>
32
33 <record id="invoice_form" model="ir.ui.view">
34 <field name="name">account.invoice.form</field>
35 <field name="model">account.invoice</field>
36 <field name="inherit_id" ref="account.invoice_form"/>
37 <field
38 name="groups_id"
39 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
40 <field name="priority">4</field>
41 <field name="arch" type="xml">
42 <notebook position="inside">
43 <page
44 string="Other Currencies"
45 attrs="{'invisible': [('state', '==', 'draft')]}">
46 <group>
47 <group>
48 <field name="amount_untaxed_eur"/>
49 <field name="amount_untaxed_usd"/>
50 </group>
51 <group>
52 <field name="rate_eur"/>
53 <field name="rate_usd"/>
54 </group>
55 </group>
56 </page>
57 </notebook>
58 </field>
59 </record>
60
61 <record id="invoice_tree" model="ir.ui.view">
62 <field name="name">account.invoice.tree</field>
63 <field name="model">account.invoice</field>
64 <field name="inherit_id" ref="account.invoice_tree"/>
65 <field
66 name="groups_id"
67 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
68 <field name="arch" type="xml">
69 <field name="amount_untaxed" position="replace">
70 <field name="amount_untaxed" string="Untaxed"/>
71 </field>
72 <field name="amount_total" position="replace">
73 <field name="amount_total"/>
74 <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/>
75 <field name="amount_untaxed_usd" sum="Total Untaxed USD"/>
76 </field>
77 </field>
78 </record>
79
80 </data>
81</openerp>
082
=== added directory 'purchase_alternate_currency'
=== added file 'purchase_alternate_currency/__init__.py'
--- purchase_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import model # noqa
023
=== added file 'purchase_alternate_currency/__openerp__.py'
--- purchase_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,54 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 'name': 'Purchase Alternate Currency',
23 'version': '1.0',
24 'category': 'Generic Modules/Purchase',
25 'description': """
26Purchase Alternate Currency
27===========================
28
29This module shows the value untaxed total of the purchase order in two, fixed
30alternate currencies. These two currencies are hardcoded.
31
32The totals are written at the moment when the order is confirmed. The rate
33used is stored, too.
34
35Contributors
36------------
37
38 * Leonardo Pistone <leonardo.pistone@camptocamp.com>
39
40""",
41 'author': 'Camptocamp',
42 'depends': ['purchase'],
43 'website': 'http://www.camptocamp.com',
44 'data': [
45 'view/purchase.xml',
46 ],
47 'test': [
48 'test/set_rate.yml',
49 'test/purchase_alternate_currency.yml',
50 ],
51 'demo': [],
52 'installable': True,
53 'active': False,
54}
055
=== added directory 'purchase_alternate_currency/model'
=== added file 'purchase_alternate_currency/model/__init__.py'
--- purchase_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import purchase # noqa
023
=== added file 'purchase_alternate_currency/model/purchase.py'
--- purchase_alternate_currency/model/purchase.py 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/model/purchase.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,90 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import openerp.addons.decimal_precision as dp
24
25
26class PurchaseOrder(orm.Model):
27 _inherit = 'purchase.order'
28
29 _columns = {
30 'rate_eur': fields.float(
31 'EUR Rate when confirmed', digits=(12, 6),
32 readonly=True,
33 help='The rate used when the order was confirmed'),
34 'rate_usd': fields.float(
35 'USD Rate when confirmed', digits=(12, 6),
36 readonly=True,
37 help='The rate used when the order was confirmed'),
38 'amount_untaxed_eur': fields.float(
39 'EUR Untaxed',
40 digits_compute=dp.get_precision('Account'),
41 readonly=True,
42 help='Untaxed Amount in EUR '
43 'computed at when the order is confirmed',
44 ),
45 'amount_untaxed_usd': fields.float(
46 'USD Untaxed',
47 digits_compute=dp.get_precision('Account'),
48 readonly=True,
49 help='Untaxed Amount in USD '
50 'computed at when the order is confirmed',
51 ),
52 }
53
54 def wkf_confirm_order(self, cr, uid, ids, context=None):
55 super(PurchaseOrder, self).wkf_confirm_order(cr, uid, ids, context)
56
57 currency_obj = self.pool['res.currency']
58 mod_obj = self.pool['ir.model.data']
59 eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1]
60 usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1]
61 eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id],
62 context=context)
63
64 for order in self.browse(cr, uid, ids, context=context):
65 order.write({
66 'rate_eur': currency_obj._get_conversion_rate(
67 cr, uid, order.currency_id, eur, context=context),
68 'rate_usd': currency_obj._get_conversion_rate(
69 cr, uid, order.currency_id, usd, context=context),
70 'amount_untaxed_eur': currency_obj.compute(
71 cr, uid, order.currency_id.id, eur_id,
72 order.amount_untaxed, context=context),
73 'amount_untaxed_usd': currency_obj.compute(
74 cr, uid, order.currency_id.id, usd_id,
75 order.amount_untaxed, context=context),
76 })
77
78 return True
79
80 def copy_data(self, cr, uid, id, default, context):
81 if default is None:
82 default = {}
83
84 default.update({
85 field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur',
86 'rate_usd', 'amount_untaxed_usd')
87 })
88
89 return super(PurchaseOrder, self).copy_data(cr, uid, id, default,
90 context)
091
=== added directory 'purchase_alternate_currency/test'
=== added file 'purchase_alternate_currency/test/purchase_alternate_currency.yml'
--- purchase_alternate_currency/test/purchase_alternate_currency.yml 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/test/purchase_alternate_currency.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,35 @@
1-
2 I change the currency of the default pricelist to PLN
3-
4 !record {model: product.pricelist, id: purchase.list0}:
5 currency_id: base.PLN
6-
7 I create a purchase order
8-
9 !record {model: purchase.order, id: order1}:
10 partner_id: base.res_partner_1
11 order_line:
12 - product_id: product.product_product_1
13 - product_id: product.product_product_2
14-
15 I confirm it
16-
17 !workflow {model: purchase.order, action: purchase_confirm, ref: order1}
18-
19 I check that the currency is PLN
20-
21 !assert {model: purchase.order, id: order1}:
22 - currency_id.name == u'PLN'
23-
24 I check the total
25-
26 !assert {model: purchase.order, id: order1}:
27 - amount_untaxed == 188.62
28-
29 I check the total in alternate currencies and the rates
30-
31 !assert {model: purchase.order, id: order1}:
32 - rate_eur == 0.243873
33 - rate_usd == 0.317035
34 - amount_untaxed_eur == 46.00
35 - amount_untaxed_usd == 59.80
036
=== added file 'purchase_alternate_currency/test/set_rate.yml'
--- purchase_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,10 @@
1-
2 I set currency rates for USD because we don't know today's date
3-
4 !record {model: res.currency.rate, id: base.rateUSD}:
5 rate: 1.3
6-
7 I set the same date for the second half of the year
8-
9 !record {model: res.currency.rate, id: base.rateUSDbis}:
10 rate: 1.3
011
=== added directory 'purchase_alternate_currency/view'
=== added file 'purchase_alternate_currency/view/purchase.xml'
--- purchase_alternate_currency/view/purchase.xml 1970-01-01 00:00:00 +0000
+++ purchase_alternate_currency/view/purchase.xml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,54 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="purchase_order_form" model="ir.ui.view">
6 <field name="name">purchase.order.form</field>
7 <field name="model">purchase.order</field>
8 <field name="inherit_id" ref="purchase.purchase_order_form"/>
9 <field
10 name="groups_id"
11 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
12 <field name="arch" type="xml">
13
14 <notebook position="inside">
15 <page
16 string="Other Currencies"
17 attrs="{'invisible': [('state','in', ('draft', 'sent'))]}">
18 <group>
19 <group>
20 <field name="amount_untaxed_eur"/>
21 <field name="amount_untaxed_usd"/>
22 </group>
23 <group>
24 <field name="rate_eur"/>
25 <field name="rate_usd"/>
26 </group>
27 </group>
28 </page>
29 </notebook>
30 </field>
31 </record>
32
33 <record id="purchase_order_tree" model="ir.ui.view">
34 <field name="name">purchase.order.tree</field>
35 <field name="model">purchase.order</field>
36 <field name="inherit_id" ref="purchase.purchase_order_tree"/>
37 <field
38 name="groups_id"
39 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
40 <field name="arch" type="xml">
41 <field name="amount_untaxed" position="replace">
42 <field name="currency_id" string="Currency"/>
43 <field name="amount_untaxed" string="Untaxed"/>
44 </field>
45 <field name="amount_total" position="replace">
46 <field name="amount_total"/>
47 <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/>
48 <field name="amount_untaxed_usd" sum="Total Untaxed USD"/>
49 </field>
50 </field>
51 </record>
52
53 </data>
54</openerp>
055
=== added directory 'sale_alternate_currency'
=== added file 'sale_alternate_currency/__init__.py'
--- sale_alternate_currency/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import model # noqa
023
=== added file 'sale_alternate_currency/__openerp__.py'
--- sale_alternate_currency/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/__openerp__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,54 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 'name': 'Sale Alternate Currency',
23 'version': '1.0',
24 'category': 'Generic Modules/Sale',
25 'description': """
26Sale Alternate Currency
27=======================
28
29This module shows the value untaxed total of the sale order in two, fixed
30alternate currencies. These two currencies are hardcoded.
31
32The totals are written at the moment when the order is confirmed. The rate
33used is stored, too.
34
35Contributors
36------------
37
38 * Leonardo Pistone <leonardo.pistone@camptocamp.com>
39
40""",
41 'author': 'Camptocamp',
42 'depends': ['sale'],
43 'website': 'http://www.camptocamp.com',
44 'data': [
45 'view/sale.xml',
46 ],
47 'test': [
48 'test/set_rate.yml',
49 'test/sale_alternate_currency.yml',
50 ],
51 'demo': [],
52 'installable': True,
53 'active': False,
54}
055
=== added directory 'sale_alternate_currency/model'
=== added file 'sale_alternate_currency/model/__init__.py'
--- sale_alternate_currency/model/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/model/__init__.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from . import sale # noqa
023
=== added file 'sale_alternate_currency/model/sale.py'
--- sale_alternate_currency/model/sale.py 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/model/sale.py 2014-07-23 10:29:51 +0000
@@ -0,0 +1,89 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Leonardo Pistone
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import openerp.addons.decimal_precision as dp
24
25
26class SaleOrder(orm.Model):
27 _inherit = 'sale.order'
28
29 _columns = {
30 'rate_eur': fields.float(
31 'EUR Rate when confirmed', digits=(12, 6),
32 readonly=True,
33 help='The rate used when the order was confirmed'),
34 'rate_usd': fields.float(
35 'USD Rate when confirmed', digits=(12, 6),
36 readonly=True,
37 help='The rate used when the order was confirmed'),
38 'amount_untaxed_eur': fields.float(
39 'EUR Untaxed',
40 digits_compute=dp.get_precision('Account'),
41 readonly=True,
42 help='Untaxed Amount in EUR '
43 'computed at when the order is confirmed',
44 ),
45 'amount_untaxed_usd': fields.float(
46 'USD Untaxed',
47 digits_compute=dp.get_precision('Account'),
48 readonly=True,
49 help='Untaxed Amount in USD '
50 'computed at when the order is confirmed',
51 ),
52 }
53
54 def action_wait(self, cr, uid, ids, context=None):
55 super(SaleOrder, self).action_wait(cr, uid, ids, context)
56
57 currency_obj = self.pool['res.currency']
58 mod_obj = self.pool['ir.model.data']
59 eur_id = mod_obj.get_object_reference(cr, uid, 'base', 'EUR')[1]
60 usd_id = mod_obj.get_object_reference(cr, uid, 'base', 'USD')[1]
61 eur, usd = currency_obj.browse(cr, uid, [eur_id, usd_id],
62 context=context)
63
64 for order in self.browse(cr, uid, ids, context=context):
65 order.write({
66 'rate_eur': currency_obj._get_conversion_rate(
67 cr, uid, order.currency_id, eur, context=context),
68 'rate_usd': currency_obj._get_conversion_rate(
69 cr, uid, order.currency_id, usd, context=context),
70 'amount_untaxed_eur': currency_obj.compute(
71 cr, uid, order.currency_id.id, eur_id,
72 order.amount_untaxed, context=context),
73 'amount_untaxed_usd': currency_obj.compute(
74 cr, uid, order.currency_id.id, usd_id,
75 order.amount_untaxed, context=context),
76 })
77
78 return True
79
80 def copy_data(self, cr, uid, id, default, context):
81 if default is None:
82 default = {}
83
84 default.update({
85 field: 0.0 for field in ('rate_eur', 'amount_untaxed_eur',
86 'rate_usd', 'amount_untaxed_usd')
87 })
88
89 return super(SaleOrder, self).copy_data(cr, uid, id, default, context)
090
=== added directory 'sale_alternate_currency/test'
=== added file 'sale_alternate_currency/test/sale_alternate_currency.yml'
--- sale_alternate_currency/test/sale_alternate_currency.yml 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/test/sale_alternate_currency.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,36 @@
1-
2 I change the currency of the default pricelist to PLN
3-
4 !record {model: product.pricelist, id: product.list0}:
5 currency_id: base.PLN
6-
7 I create a sale order
8-
9 !record {model: sale.order, id: order1}:
10 partner_id: base.res_partner_1
11 order_line:
12 - product_id: product.product_product_1
13 product_uom_qty: 5
14 - product_id: product.product_product_2
15-
16 I confirm it
17-
18 !workflow {model: sale.order, action: order_confirm, ref: order1}
19-
20 I check that the currency is PLN
21-
22 !assert {model: sale.order, id: order1}:
23 - currency_id.name == u'PLN'
24-
25 I check the total
26-
27 !assert {model: sale.order, id: order1}:
28 - amount_untaxed == 787.29
29-
30 I check the total in alternate currencies and the rates
31-
32 !assert {model: sale.order, id: order1}:
33 - rate_eur == 0.243873
34 - rate_usd == 0.317035
35 - amount_untaxed_eur == 192.00
36 - amount_untaxed_usd == 249.60
037
=== added file 'sale_alternate_currency/test/set_rate.yml'
--- sale_alternate_currency/test/set_rate.yml 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/test/set_rate.yml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,10 @@
1-
2 I set currency rates for USD because we don't know today's date
3-
4 !record {model: res.currency.rate, id: base.rateUSD}:
5 rate: 1.3
6-
7 I set the same date for the second half of the year
8-
9 !record {model: res.currency.rate, id: base.rateUSDbis}:
10 rate: 1.3
011
=== added directory 'sale_alternate_currency/view'
=== added file 'sale_alternate_currency/view/sale.xml'
--- sale_alternate_currency/view/sale.xml 1970-01-01 00:00:00 +0000
+++ sale_alternate_currency/view/sale.xml 2014-07-23 10:29:51 +0000
@@ -0,0 +1,68 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="view_order_form" model="ir.ui.view">
6 <field name="name">sale.order.form</field>
7 <field name="model">sale.order</field>
8 <field name="inherit_id" ref="sale.view_order_form"/>
9 <field
10 name="groups_id"
11 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
12 <field name="arch" type="xml">
13
14 <notebook position="inside">
15 <page string="Other Currencies"
16 attrs="{'invisible': [('state','in', ('draft', 'sent'))]}">
17 <group>
18 <group>
19 <field name="amount_untaxed_eur"/>
20 <field name="amount_untaxed_usd"/>
21 </group>
22 <group>
23 <field name="rate_eur"/>
24 <field name="rate_usd"/>
25 </group>
26 </group>
27 </page>
28 </notebook>
29 </field>
30 </record>
31
32 <record id="view_order_tree" model="ir.ui.view">
33 <field name="name">sale.order.tree</field>
34 <field name="model">sale.order</field>
35 <field name="inherit_id" ref="sale.view_order_tree"/>
36 <field
37 name="groups_id"
38 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
39 <field name="arch" type="xml">
40 <field name="amount_total" position="replace">
41 <field name="currency_id" string="Currency"/>
42 <field name="amount_total"/>
43 <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/>
44 <field name="amount_untaxed_usd" sum="Total Untaxed USD"/>
45 </field>
46 </field>
47 </record>
48
49 <record id="view_quotation_tree" model="ir.ui.view">
50 <field name="name">sale.order.tree</field>
51 <field name="model">sale.order</field>
52 <field name="inherit_id" ref="sale.view_quotation_tree"/>
53 <field
54 name="groups_id"
55 eval="[(6, 0, [ref('base.group_multi_currency')])]"/>
56 <field name="arch" type="xml">
57 <field name="amount_total" position="replace">
58 <field name="currency_id" string="Currency"/>
59 <field name="amount_total"/>
60 <field name="amount_untaxed" string="Untaxed"/>
61 <field name="amount_untaxed_eur" sum="Total Untaxed EUR"/>
62 <field name="amount_untaxed_usd" sum="Total Untaxed USD"/>
63 </field>
64 </field>
65 </record>
66
67 </data>
68</openerp>

Subscribers

People subscribed via source and target branches

to all changes: