-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,237 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
sales_analysis_converting_sale_order_line_in_base_currency/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 - present Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################### | ||
from . import models |
74 changes: 74 additions & 0 deletions
74
sales_analysis_converting_sale_order_line_in_base_currency/__openerp__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 - present Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################### | ||
|
||
{ | ||
'name': 'sales Analysis converting sale order line in base currency', | ||
'version': '0.1', | ||
'author': 'Savoir-faire Linux', | ||
'maintainer': 'Savoir-faire Linux', | ||
'website': 'http://www.savoirfairelinux.com', | ||
'license': 'AGPL-3', | ||
'category': 'Others', | ||
'summary': 'Sales Analysis conversion of price to base currency', | ||
'description': """ | ||
Sales analysis reporting in base currency | ||
========================================= | ||
When you have several invoices, Odoo displays the | ||
total amounts for a defined period in the Reporting | ||
Module, Sales Analysis entry. This total is wrong | ||
if you have made sales in different currencies as | ||
Odoo ignores currencies in this instance. | ||
This module therefore allows the system to assign a | ||
converted amount in the default company currency | ||
and associates it to a sale.order made in a | ||
different currency. The rate is chosen when the | ||
sales order is set to done. | ||
The sales analysis reporting tool is therefore | ||
modified to present a consistent total for your | ||
sales in your base currency. | ||
This module has dependencies to : | ||
--------------------------------- | ||
* sale | ||
**Warning : this module will not work in a multi | ||
company setup** | ||
Contributors | ||
------------ | ||
* Loïc Faure-Lacroix <loic.lacroix@savoirfairelinux.com> | ||
""", | ||
'depends': [ | ||
'base', | ||
'product', | ||
'sale', | ||
], | ||
'external_dependencies': { | ||
'python': [], | ||
}, | ||
'data': [ | ||
'views/sale_order.xml', | ||
], | ||
'installable': True, | ||
} |
23 changes: 23 additions & 0 deletions
23
sales_analysis_converting_sale_order_line_in_base_currency/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 - present Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################### | ||
from . import sale_order | ||
from . import sale_order_line |
87 changes: 87 additions & 0 deletions
87
sales_analysis_converting_sale_order_line_in_base_currency/models/sale_order.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################### | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 - present Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################### | ||
from openerp.osv import fields, orm | ||
from openerp.addons.decimal_precision import get_precision | ||
|
||
|
||
class SaleOrder(orm.Model): | ||
|
||
"""Override the sale.order model.""" | ||
|
||
_inherit = 'sale.order' | ||
|
||
_columns = { | ||
'converted_amount_total': fields.function( | ||
lambda self, *a, **b: self._compute_converted_total(*a, **b), | ||
method=True, | ||
type='float', | ||
digits_compute=get_precision("Product Price"), | ||
string='Converted Total (Before tax)' | ||
), | ||
'converted_amount_total_untaxed': fields.function( | ||
lambda self, *a, **b: self._compute_converted_total(*a, **b), | ||
method=True, | ||
type='float', | ||
digits_compute=get_precision("Product Price"), | ||
string='Converted Total (Before tax)' | ||
), | ||
'company_currency_id': fields.related( | ||
'company_id', | ||
'currency_id', | ||
type="many2one", | ||
relation="res.currency", | ||
string="Company Currency", | ||
readonly=True, | ||
store=True | ||
), | ||
} | ||
|
||
def _compute_converted_total(self, cr, uid, ids, field_name, arg, context): | ||
res = {} | ||
|
||
for obj in self.browse(cr, uid, ids, context=context): | ||
total = 0 | ||
for line in obj.order_line: | ||
total += line.converted_amount_subtotal | ||
res[obj.id] = total | ||
|
||
return res | ||
|
||
def action_button_confirm(self, cr, uid, ids, context=None): | ||
""" | ||
Convert unit_price using the line and company currencies. | ||
Convert price using the currency if necessary or set the | ||
lst_price if no conversion is necessary. The reason to skip | ||
the conversion is to reduce the amount of error with roundings. | ||
""" | ||
base_func = super(SaleOrder, self).action_button_confirm | ||
base_func(cr, uid, ids, context=context) | ||
|
||
for o in self.browse(cr, uid, ids, context=context): | ||
base_currency = o.company_id.currency_id.rate | ||
|
||
for line in o.order_line: | ||
new_price = line.compute_amount_currency(base_currency) | ||
line.write({ | ||
"amount_currency_calculated": new_price | ||
}) |
Oops, something went wrong.