diff --git a/odoo/addons/base/__manifest__.py b/odoo/addons/base/__manifest__.py index cbea1700eda..87c59505a57 100644 --- a/odoo/addons/base/__manifest__.py +++ b/odoo/addons/base/__manifest__.py @@ -12,6 +12,7 @@ The kernel of Odoo, needed for all installation. """, 'depends': [], 'data': [ + 'data/res_bank.xml', 'data/res.lang.csv', 'data/res_lang_data.xml', 'data/res_partner_data.xml', diff --git a/odoo/addons/base/data/res_bank.xml b/odoo/addons/base/data/res_bank.xml new file mode 100644 index 00000000000..329bba052ac --- /dev/null +++ b/odoo/addons/base/data/res_bank.xml @@ -0,0 +1,11 @@ + + + + + + Reserve + + + + + diff --git a/odoo/addons/base/data/res_currency_data.xml b/odoo/addons/base/data/res_currency_data.xml index 2870bb60240..139db851ba7 100644 --- a/odoo/addons/base/data/res_currency_data.xml +++ b/odoo/addons/base/data/res_currency_data.xml @@ -4,6 +4,7 @@ USD + United States dollar $ 0.01 before @@ -13,6 +14,7 @@ VEF + The Bolívar Fuerte Bs.F 0.0001 @@ -22,6 +24,7 @@ CAD + Canadian dollar $ 0.01 @@ -31,6 +34,7 @@ CHF + Swiss franc CHF 0.01 @@ -40,6 +44,7 @@ BRL + Brazilian real R$ 0.01 @@ -50,6 +55,7 @@ CNY + Chinese yuan ¥ 0.01 @@ -60,6 +66,7 @@ COP + Colombian peso $ 0.01 @@ -70,6 +77,7 @@ CZK + Czech koruna Kč 0.01 @@ -79,6 +87,7 @@ DKK + Danish krone kr 0.01 before @@ -89,6 +98,7 @@ HUF + Hungarian forint Ft 1.00 @@ -98,6 +108,7 @@ IDR + Indonesian rupiah Rp 1.00 before @@ -108,6 +119,7 @@ LVL + Latvian lats Ls 0.01 @@ -117,6 +129,7 @@ NOK + Norwegian krone kr 0.01 before @@ -127,6 +140,7 @@ XPF + CFP franc XPF 1.00 @@ -136,6 +150,7 @@ PAB + Panamanian balboa B/. 0.01 @@ -145,6 +160,7 @@ PLN + Polish złoty zł 0.01 @@ -154,6 +170,7 @@ SEK + Swedish krona kr 0.01 @@ -163,6 +180,7 @@ ARS + Argentine peso $ 0.01 before @@ -173,6 +191,7 @@ INR + Indian rupee ₹ 0.01 before @@ -183,6 +202,7 @@ AUD + Australian dollar $ before 0.01 @@ -193,6 +213,7 @@ UAH + Ukrainian hryvnia ₴ 0.01 @@ -202,6 +223,7 @@ VND + Vietnamese đồng ₫ 1.00 @@ -211,6 +233,7 @@ HKD + Hong Kong dollar $ 0.01 @@ -220,6 +243,7 @@ JPY + Japanese yen ¥ 1.00 @@ -230,6 +254,7 @@ BGN + Bulgarian lev лв 0.01 @@ -239,6 +264,7 @@ LTL + Lithuanian litas Lt 0.01 @@ -248,6 +274,7 @@ RON + Romanian leu lei 0.01 @@ -257,6 +284,7 @@ HRK + Croatian kuna kn 0.01 @@ -266,6 +294,7 @@ RUB + Russian ruble руб 0.01 @@ -275,6 +304,7 @@ TRY + Turkish lira ₺ 0.01 @@ -284,6 +314,7 @@ KRW + South Korean won ₩ 0.01 @@ -293,6 +324,7 @@ MXN + Mexican peso $ 0.01 @@ -303,6 +335,7 @@ MYR + Malaysian ringgit RM 0.01 @@ -312,6 +345,7 @@ NZD + New Zealand dollar $ before 0.01 @@ -322,6 +356,7 @@ PHP + Philippine peso Php 0.01 @@ -331,6 +366,7 @@ SGD + Singapore dollar S$ 0.01 @@ -341,6 +377,7 @@ ZAR + South African rand R 0.01 before @@ -349,13 +386,9 @@ Cents - - Reserve - - - CRC + Costa Rican colón 0.01 ₡ before @@ -366,6 +399,7 @@ MUR + Mauritian rupee Rs 0.01 @@ -375,6 +409,7 @@ XOF + West African CFA franc CFA 1 @@ -384,6 +419,7 @@ XAF + Central African CFA franc FCFA 1 @@ -393,6 +429,7 @@ UGX + Ugandan shilling USh 1 @@ -402,6 +439,7 @@ HNL + Honduran lempira L 0.01 @@ -411,6 +449,7 @@ CLP + Chilean peso $ 1 @@ -421,6 +460,7 @@ UYU + Uruguayan peso $ 0.01 @@ -430,6 +470,7 @@ AFN + Afghan afghani Afs 0.01 @@ -439,6 +480,7 @@ AOA + Angolan kwanza Kz 0.01 @@ -448,6 +490,7 @@ XCD + Eastern Caribbean dollar $ 0.01 @@ -457,6 +500,7 @@ AMD + Armenian dram դր. 0.01 @@ -466,6 +510,7 @@ AWG + Aruban florin Afl. 0.01 @@ -475,6 +520,7 @@ AZN + Azerbaijani manat m 0.01 @@ -484,6 +530,7 @@ BSD + Bahamian dollar B$ 0.01 @@ -493,6 +540,7 @@ BHD + Bahraini dinar BD 0.001 @@ -502,6 +550,7 @@ BDT + Bangladeshi taka ৳ 0.01 @@ -511,6 +560,7 @@ BBD + Barbadian dollar Bds$ 0.01 @@ -520,6 +570,7 @@ BYR + Belarusian ruble BR 0.01 @@ -529,6 +580,7 @@ BYN + Belarusian ruble Br 0.01 @@ -538,6 +590,7 @@ BZD + Belize dollar BZ$ 0.01 @@ -547,6 +600,7 @@ BMD + Bermudian dollar BD$ 0.01 @@ -556,6 +610,7 @@ BTN + Bhutanese ngultrum Nu. 0.01 @@ -565,6 +620,7 @@ BOB + Bolivian boliviano Bs. 0.01 @@ -574,6 +630,7 @@ BAM + Bosnia and Herzegovina convertible mark KM 0.01 @@ -583,6 +640,7 @@ BWP + Botswana pula P 0.01 @@ -592,6 +650,7 @@ BIF + Burundian franc FBu 0.01 @@ -601,6 +660,7 @@ KHR + Cambodian riel ៛ 0.01 @@ -610,6 +670,7 @@ KYD + Cayman Islands dollar $ 0.01 @@ -619,6 +680,7 @@ KMF + Comorian franc CF 0.01 @@ -628,6 +690,7 @@ CDF + Congolese franc Fr 0.01 @@ -637,6 +700,7 @@ CUP + Cuban peso $ 0.01 @@ -646,6 +710,7 @@ ANG + Netherlands Antillean guilder ƒ 0.01 @@ -655,6 +720,7 @@ CYP + Cypriot pound £ 0.01 @@ -664,6 +730,7 @@ DJF + Djiboutian franc Fdj 0.01 @@ -673,6 +740,7 @@ DOP + Dominican peso RD$ 0.01 @@ -683,6 +751,7 @@ ECS + Ecuadorian sucre S/. 0.01 @@ -692,6 +761,7 @@ EGP + Egyptian pound E£ 0.01 @@ -701,6 +771,7 @@ SVC + Salvadoran Colon ¢ 0.01 @@ -710,6 +781,7 @@ ERN + Eritrean nakfa Nfk 0.01 @@ -719,6 +791,7 @@ ETB + Ethiopian birr Br 0.01 @@ -728,6 +801,7 @@ FKP + Falkland Islands pound £ 0.01 @@ -737,6 +811,7 @@ FJD + Fijian dollar FJ$ 0.01 @@ -746,6 +821,7 @@ GEL + Georgian lari ლ 0.01 @@ -755,6 +831,7 @@ GIP + Gibraltar pound £ 0.01 @@ -764,6 +841,7 @@ QTQ + Guatemalan Quetzal Q 0.01 @@ -773,6 +851,7 @@ GNF + Guinean franc FG 0.01 @@ -782,6 +861,7 @@ GYD + Guyanese dollar $ 0.01 @@ -791,6 +871,7 @@ HTG + Haitian gourde G 0.01 @@ -800,6 +881,7 @@ ISK + Icelandic króna kr 0.01 @@ -809,6 +891,7 @@ IRR + Iranian rial ﷼ 0.01 @@ -818,6 +901,7 @@ IQD + Iraqi dinar ع.د 0.001 @@ -827,6 +911,7 @@ ILS + Israeli new shekel ₪ 0.01 @@ -836,6 +921,7 @@ JMD + Jamaican dollar $ 0.01 @@ -845,6 +931,7 @@ JOD + Jordanian dinar د.ا 0.001 @@ -854,6 +941,7 @@ KZT + Kazakhstani tenge лв 0.01 @@ -863,6 +951,7 @@ KES + Kenyan shilling KSh 0.01 @@ -872,6 +961,7 @@ KWD + Kuwaiti dinar د.ك 0.001 @@ -881,6 +971,7 @@ KGS + Kyrgyzstani som лв 0.01 @@ -890,6 +981,7 @@ LAK + Lao kip ₭ 0.01 @@ -899,6 +991,7 @@ LBP + Lebanese pound ل.ل 0.01 @@ -908,6 +1001,7 @@ LSL + Lesotho loti M 0.01 @@ -917,6 +1011,7 @@ LRD + Liberian dollar L$ 0.01 @@ -926,6 +1021,7 @@ LYD + Libyan dinar ل.د 0.001 @@ -935,6 +1031,7 @@ MOP + Macanese pataca MOP$ 0.01 @@ -944,6 +1041,7 @@ MKD + Macedonian denar ден 0.01 @@ -953,6 +1051,7 @@ MGA + Malagasy ariary Ar 0.01 @@ -962,6 +1061,7 @@ MWK + Malawian kwacha MK 0.01 @@ -971,6 +1071,7 @@ MVR + Maldivian rufiyaa .ރ 0.01 @@ -980,6 +1081,7 @@ MRO + Mauritanian ouguiya (old) UM 0.01 @@ -989,6 +1091,7 @@ MRU + Mauritanian ouguiya UM 0.01 @@ -998,6 +1101,7 @@ MDL + Moldovan leu L 0.01 @@ -1007,6 +1111,7 @@ MNT + Mongolian tögrög ₮ 0.01 @@ -1016,6 +1121,7 @@ MAD + Moroccan dirham DH 0.01 @@ -1025,6 +1131,7 @@ BND + Brunei dollar $ 0.01 @@ -1034,6 +1141,7 @@ DZD + Algerian dinar DA 0.01 @@ -1043,6 +1151,7 @@ GHS + Ghanaian cedi GH¢ 0.01 @@ -1052,6 +1161,7 @@ GMD + Gambian dalasi D 0.01 @@ -1061,6 +1171,7 @@ ZRZ + Zairean zaire Ƶ 0.01 @@ -1070,6 +1181,7 @@ MZN + Mozambican metical MT 0.01 @@ -1079,6 +1191,7 @@ MMK + Burmese kyat K 0.01 @@ -1088,6 +1201,7 @@ NAD + Namibian dollar $ 0.01 @@ -1097,6 +1211,7 @@ NPR + Nepalese rupee ₨ 0.01 @@ -1106,6 +1221,7 @@ ALL + Albanian lek L 0.01 @@ -1115,6 +1231,7 @@ NIO + Nicaraguan córdoba C$ 0.01 @@ -1124,6 +1241,7 @@ NGN + Nigerian naira ₦ 0.01 @@ -1133,6 +1251,7 @@ KPW + North Korean won ₩ 0.01 @@ -1142,6 +1261,7 @@ ZWL + Zimbabwean dollar Z$ 0.01 @@ -1151,6 +1271,7 @@ ZMW + Zambian kwacha ZK 0.01 @@ -1160,6 +1281,7 @@ YER + Yemeni rial ﷼ 0.01 @@ -1169,6 +1291,7 @@ EUR + Euro € 0.01 Euros @@ -1177,6 +1300,7 @@ VUV + Vanuatu vatu VT 0.01 @@ -1185,6 +1309,7 @@ UZS + Uzbekistani soʻm лв 0.01 @@ -1194,6 +1319,7 @@ AED + United Arab Emirates dirham د.إ 0.01 @@ -1203,6 +1329,7 @@ UAG + Ukraine Hryvnia ₴ 0.01 @@ -1212,6 +1339,7 @@ TMT + Turkmenistan manat T 0.01 @@ -1221,6 +1349,7 @@ TND + Tunisian dinar DT 0.001 @@ -1230,6 +1359,7 @@ TTD + Trinidad and Tobago dollar $ 0.01 @@ -1239,6 +1369,7 @@ TOP + Tongan paʻanga T$ 0.01 @@ -1248,6 +1379,7 @@ THB + Thai baht ฿ 0.01 @@ -1257,6 +1389,7 @@ TZS + Tanzanian shilling TSh 0.01 @@ -1266,6 +1399,7 @@ TJS + Tajikistani somoni TJS 0.01 @@ -1275,6 +1409,7 @@ TWD + New Taiwan dollar NT$ 0.01 @@ -1284,6 +1419,7 @@ SYP + Syrian pound £ 0.01 @@ -1293,6 +1429,7 @@ SZL + Swazi lilangeni E 0.01 @@ -1302,6 +1439,7 @@ SRD + Surinamese dollar $ 0.01 @@ -1311,6 +1449,7 @@ SDG + Sudanese pound ج.س. 0.01 @@ -1318,6 +1457,7 @@ LKR + Sri Lankan rupee Rs 0.01 @@ -1327,6 +1467,7 @@ SSP + South Sudanese pound £ 0.01 @@ -1336,6 +1477,7 @@ GBP + British pound £ 0.01 before @@ -1346,6 +1488,7 @@ SOD + Somalian shilling Sh. 0.01 @@ -1355,6 +1498,7 @@ SBD + Solomon Islands dollar SI$ 0.01 @@ -1364,6 +1508,7 @@ SLL + Sierra Leonean leone Le 0.01 @@ -1373,6 +1518,7 @@ SCR + Seychellois rupee SR 0.01 @@ -1382,6 +1528,7 @@ RSD + Serbian dinar din. 0.01 @@ -1391,6 +1538,7 @@ SAR + Saudi riyal SR 0.01 @@ -1400,6 +1548,7 @@ STD + São Tomé and Príncipe dobra Db 0.01 @@ -1409,6 +1558,7 @@ ITL + Italian Lira ₤ 0.01 @@ -1418,6 +1568,7 @@ WST + Samoan tālā WS$ 0.01 @@ -1427,6 +1578,7 @@ SHP + Saint Helena pound £ 0.01 @@ -1436,6 +1588,7 @@ RWF + Rwandan franc RF 0.01 @@ -1445,6 +1598,7 @@ RUR + Russian Ruble R 0.01 @@ -1454,14 +1608,17 @@ QAR + Qatari riyal QR 0.01 Rial Dirham + PLZ + Polish złoty zł 0.01 @@ -1471,6 +1628,7 @@ PEN + Peruvian sol S/ 0.01 @@ -1481,6 +1639,7 @@ PYG + Paraguayan guaraní ₲ 0.01 @@ -1490,6 +1649,7 @@ PGK + Papua New Guinean kina K 0.01 @@ -1499,6 +1659,7 @@ PKR + Pakistani rupee Rs. 0.01 @@ -1508,6 +1669,7 @@ OMR + Omani rial ر.ع. 0.001 @@ -1517,6 +1679,7 @@ CVE + Cape Verdean escudo $ 0.01 @@ -1526,6 +1689,7 @@ SKK + Slovak koruna Sk 0.01 @@ -1535,6 +1699,7 @@ YUM + Yugoslav dinar дин. 0.01 @@ -1544,6 +1709,7 @@ GTQ + Guatemalan quetzal Q 0.01 diff --git a/odoo/addons/base/data/res_currency_rate_demo.xml b/odoo/addons/base/data/res_currency_rate_demo.xml index aafad23e7e1..ab842468a2d 100644 --- a/odoo/addons/base/data/res_currency_rate_demo.xml +++ b/odoo/addons/base/data/res_currency_rate_demo.xml @@ -11,7 +11,7 @@ 1.5289 - + diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 23c87f7859e..db652a9f3c3 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -10,7 +10,6 @@ import re from odoo import api, fields, models, tools, _, Command from odoo.exceptions import ValidationError, UserError from odoo.modules.module import get_resource_path - from random import randrange from PIL import Image diff --git a/odoo/addons/base/models/res_currency.py b/odoo/addons/base/models/res_currency.py index 1ca67dc53bb..a275684ea1d 100644 --- a/odoo/addons/base/models/res_currency.py +++ b/odoo/addons/base/models/res_currency.py @@ -5,8 +5,8 @@ import logging import math import re import time -import traceback +from lxml import etree from odoo import api, fields, models, tools, _ _logger = logging.getLogger(__name__) @@ -27,18 +27,25 @@ class Currency(models.Model): # Note: 'code' column was removed as of v6.0, the 'name' should now hold the ISO code. name = fields.Char(string='Currency', size=3, required=True, help="Currency Code (ISO 4217)") + full_name = fields.Char(string='Name') symbol = fields.Char(help="Currency sign, to be used when printing amounts.", required=True) rate = fields.Float(compute='_compute_current_rate', string='Current Rate', digits=0, help='The rate of the currency to the currency of rate 1.') + inverse_rate = fields.Float(compute='_compute_current_rate', digits=0, readonly=True, + help='The currency of rate 1 to the rate of the currency.') + rate_string = fields.Char(compute='_compute_current_rate') rate_ids = fields.One2many('res.currency.rate', 'currency_id', string='Rates') - rounding = fields.Float(string='Rounding Factor', digits=(12, 6), default=0.01) - decimal_places = fields.Integer(compute='_compute_decimal_places', store=True) + rounding = fields.Float(string='Rounding Factor', digits=(12, 6), default=0.01, + help='Amounts in this currency are rounded off to the nearest multiple of the rounding factor.') + decimal_places = fields.Integer(compute='_compute_decimal_places', store=True, + help='Decimal places taken into account for operations on amounts in this currency. It is determined by the rounding factor.') active = fields.Boolean(default=True) position = fields.Selection([('after', 'After Amount'), ('before', 'Before Amount')], default='after', string='Symbol Position', help="Determines where the currency symbol should be placed after or before the amount.") date = fields.Date(compute='_compute_date') currency_unit_label = fields.Char(string="Currency Unit", help="Currency Unit Name") currency_subunit_label = fields.Char(string="Currency Subunit", help="Currency Subunit Name") + is_current_company_currency = fields.Boolean(compute='_compute_is_current_company_currency') _sql_constraints = [ ('unique_name', 'unique (name)', 'The currency code must be unique!'), @@ -61,14 +68,25 @@ class Currency(models.Model): currency_rates = dict(self._cr.fetchall()) return currency_rates + @api.depends_context('company') + def _compute_is_current_company_currency(self): + for currency in self: + currency.is_current_company_currency = self.env.company.currency_id == currency + @api.depends('rate_ids.rate') def _compute_current_rate(self): date = self._context.get('date') or fields.Date.today() company = self.env['res.company'].browse(self._context.get('company_id')) or self.env.company # the subquery selects the last rate before 'date' for the given currency/company currency_rates = self._get_rates(company, date) + last_rate = self.env['res.currency.rate']._get_last_rates_for_companies(company) for currency in self: - currency.rate = currency_rates.get(currency.id) or 1.0 + currency.rate = (currency_rates.get(currency.id) or 1.0) / last_rate[company] + currency.inverse_rate = 1 / currency.rate + if currency != company.currency_id: + currency.rate_string = '1 %s = %s %s' % (company.currency_id.name, currency.rate, currency.name) + else: + currency.rate_string = '' @api.depends('rounding') def _compute_decimal_places(self): @@ -229,6 +247,20 @@ class Currency(models.Model): JOIN res_company c ON (r.company_id is null or r.company_id = c.id) """ + @api.model + def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + result = super(Currency, self)._fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + if view_type in ('tree', 'form'): + currency_name = (self.env['res.company'].browse(self._context.get('company_id')) or self.env.company).currency_id.name + doc = etree.XML(result['arch']) + for field in [['company_rate', _('Unit per %s', currency_name)], + ['inverse_company_rate', _('%s per Unit', currency_name)]]: + node = doc.xpath("//tree//field[@name='%s']" % field[0]) + if node: + node[0].set('string', field[1]) + result['arch'] = etree.tostring(doc, encoding='unicode') + return result + class CurrencyRate(models.Model): _name = "res.currency.rate" @@ -237,8 +269,26 @@ class CurrencyRate(models.Model): name = fields.Date(string='Date', required=True, index=True, default=lambda self: fields.Date.today()) - rate = fields.Float(digits=0, compute="_compute_rate", store=True, readonly=False, group_operator="avg", - help='The rate of the currency to the currency of rate 1') + rate = fields.Float( + digits=0, + group_operator="avg", + help='The rate of the currency to the currency of rate 1', + string='Technical Rate' + ) + company_rate = fields.Float( + digits=0, + compute="_compute_company_rate", + inverse="_inverse_company_rate", + group_operator="avg", + help="The currency of rate 1 to the rate of the currency.", + ) + inverse_company_rate = fields.Float( + digits=0, + compute="_compute_inverse_company_rate", + inverse="_inverse_inverse_company_rate", + group_operator="avg", + help="The currency of rate 1 to the rate of the currency.", + ) currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, required=True, ondelete="cascade") company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) @@ -248,26 +298,70 @@ class CurrencyRate(models.Model): ('currency_rate_check', 'CHECK (rate>0)', 'The currency rate must be strictly positive.'), ] + def _sanitize_vals(self, vals): + if 'inverse_company_rate' in vals and ('company_rate' in vals or 'rate' in vals): + del vals['inverse_company_rate'] + if 'company_rate' in vals and 'rate' in vals: + del vals['company_rate'] + return vals + + def write(self, vals): + return super().write(self._sanitize_vals(vals)) + + @api.model_create_multi + def create(self, vals_list): + return super().create([self._sanitize_vals(vals) for vals in vals_list]) + def _get_latest_rate(self): - return self.search([ - ('currency_id', '=', self.currency_id.id), - ('company_id', '=', self.company_id.id or self.env.company.id), - ('name', '<=', self.name or fields.Date.today()), - ], order="name desc", limit=1) + return self.currency_id.rate_ids.filtered(lambda x: ( + x.rate + and x.company_id == (self.company_id or self.env.company) + and x.name < (self.name or fields.Date.today()) + )).sorted('name')[-1:] + + def _get_last_rates_for_companies(self, companies): + return { + company: company.currency_id.rate_ids.filtered(lambda x: ( + x.rate + and x.company_id == company or not x.company_id + )).sorted('name')[-1:].rate or 1 + for company in companies + } @api.depends('currency_id', 'company_id', 'name') def _compute_rate(self): for currency_rate in self: - latest_rate = currency_rate._get_latest_rate() - currency_rate.rate = latest_rate.rate if latest_rate else 1.0 + currency_rate.rate = currency_rate.rate or self._get_latest_rate().rate or 1.0 - @api.onchange('rate') + @api.depends('rate', 'name', 'currency_id', 'company_id', 'currency_id.rate_ids.rate') + @api.depends_context('company') + def _compute_company_rate(self): + last_rate = self.env['res.currency.rate']._get_last_rates_for_companies(self.company_id | self.env.company) + for currency_rate in self: + company = currency_rate.company_id or self.env.company + currency_rate.company_rate = (currency_rate.rate or self._get_latest_rate().rate or 1.0) / last_rate[company] + + @api.onchange('company_rate') + def _inverse_company_rate(self): + last_rate = self.env['res.currency.rate']._get_last_rates_for_companies(self.company_id | self.env.company) + for currency_rate in self: + company = currency_rate.company_id or self.env.company + currency_rate.rate = currency_rate.company_rate * last_rate[company] + + @api.depends('company_rate') + def _compute_inverse_company_rate(self): + for currency_rate in self: + currency_rate.inverse_company_rate = 1.0 / currency_rate.company_rate + + @api.onchange('inverse_company_rate') + def _inverse_inverse_company_rate(self): + for currency_rate in self: + currency_rate.company_rate = 1.0 / currency_rate.inverse_company_rate + + @api.onchange('company_rate') def _onchange_rate_warning(self): - if not self.currency_id.id: - return - latest_rate = self._get_latest_rate() - if latest_rate and latest_rate.rate: + if latest_rate: diff = (latest_rate.rate - self.rate) / latest_rate.rate if abs(diff) > 0.2: return { @@ -298,3 +392,20 @@ class CurrencyRate(models.Model): name = '' operator = 'ilike' return super(CurrencyRate, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid) + + @api.model + def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + result = super(CurrencyRate, self)._fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + if view_type in ('tree'): + names = { + 'company_currency_name': (self.env['res.company'].browse(self._context.get('company_id')) or self.env.company).currency_id.name, + 'rate_currency_name': self.env['res.currency'].browse(self._context.get('active_id')).name or 'Unit', + } + doc = etree.XML(result['arch']) + for field in [['company_rate', _('%(rate_currency_name)s per %(company_currency_name)s', **names)], + ['inverse_company_rate', _('%(company_currency_name)s per %(rate_currency_name)s', **names)]]: + node = doc.xpath("//tree//field[@name='%s']" % field[0]) + if node: + node[0].set('string', field[1]) + result['arch'] = etree.tostring(doc, encoding='unicode') + return result diff --git a/odoo/addons/base/views/res_currency_views.xml b/odoo/addons/base/views/res_currency_views.xml index 1be52955800..5fbbee288e9 100644 --- a/odoo/addons/base/views/res_currency_views.xml +++ b/odoo/addons/base/views/res_currency_views.xml @@ -17,8 +17,11 @@ - + + + + @@ -32,13 +35,14 @@ - + + + - @@ -46,12 +50,15 @@ - Currency Rates + Show Currency Rates res.currency.rate tree,form [('currency_id','=', active_id)] {'default_currency_id': active_id} + + + form @@ -73,9 +80,10 @@ - - + + + @@ -88,21 +96,26 @@ + +
-
- +
+

-
+
+
+ inactive +
- Current Rate: - +
+
Last update:
@@ -117,15 +130,19 @@ res.currency
+ + + + -
-
- + @@ -134,10 +151,6 @@ - - @@ -149,10 +162,25 @@ + + + + + + + + + + + + + +
+ Currencies res.currency