Move currency to its own module
This commit is contained in:
1 parent
cf89b3fac4
commit
fec6a01c41
8 files changed
+16
-328
No files matched your search
@@ -24,7 +24,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from currency import *
|
||||
from account import *
|
||||
from fiscalyear import *
|
||||
from period import *
|
||||
|
||||
+1
-1
@@ -11,10 +11,10 @@
|
||||
'res',
|
||||
'company',
|
||||
'partner',
|
||||
'currency',
|
||||
],
|
||||
'xml': [
|
||||
'account.xml',
|
||||
'currency.xml',
|
||||
'fiscalyear.xml',
|
||||
'period.xml',
|
||||
'journal.xml',
|
||||
|
||||
+6
-6
@@ -53,7 +53,7 @@ class Type(OSV):
|
||||
def get_amount(self, cursor, user, ids, name, arg, context=None):
|
||||
company_obj = self.pool.get('company.company')
|
||||
account_obj = self.pool.get('account.account')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -175,8 +175,8 @@ class Account(OSV):
|
||||
active = fields.Boolean('Active', select=2)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
currency = fields.Function('get_currency', type='many2one',
|
||||
relation='account.currency', string='Currency')
|
||||
second_currency = fields.Many2One('account.currency', 'Secondary currency',
|
||||
relation='currency.currency', string='Currency')
|
||||
second_currency = fields.Many2One('currency.currency', 'Secondary currency',
|
||||
help='Force all moves for this account \n' \
|
||||
'to have this secondary currency.')
|
||||
type = fields.Many2One('account.account.type', 'Type', required=True,
|
||||
@@ -255,7 +255,7 @@ class Account(OSV):
|
||||
return True
|
||||
|
||||
def get_currency(self, cursor, user, ids, name, arg, context=None):
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
res = {}
|
||||
for account in self.browse(cursor,user, ids, context=context):
|
||||
res[account.id] = account.company.currency.id
|
||||
@@ -274,7 +274,7 @@ class Account(OSV):
|
||||
def get_balance(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
company_obj = self.pool.get('company.company')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
|
||||
child_ids = self.search(cursor, user, [('parents', 'child_of', ids)],
|
||||
@@ -326,7 +326,7 @@ class Account(OSV):
|
||||
res = {}
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
company_obj = self.pool.get('company.company')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
|
||||
if name not in ('credit', 'debit'):
|
||||
raise Exception('Bad argument')
|
||||
|
||||
-148
@@ -1,148 +0,0 @@
|
||||
"Currency"
|
||||
|
||||
from trytond.osv import fields, OSV, ExceptOSV
|
||||
import time
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
class Currency(OSV):
|
||||
'Currency'
|
||||
_name = 'account.currency'
|
||||
_description = __doc__
|
||||
name = fields.Char('Name', size=128, required=True, translate=True)
|
||||
code = fields.Char('Code', size=3, required=True)
|
||||
rate = fields.Function('get_rate', string='Current rate', digits=(12, 6))
|
||||
rates = fields.One2Many('account.currency.rate', 'currency', 'Rates')
|
||||
rounding = fields.Numeric('Rounding factor', digits=(12, 6))
|
||||
digits = fields.Integer('Diplay Digits')
|
||||
active = fields.Boolean('Active')
|
||||
|
||||
def __init__(self):
|
||||
super(Currency, self).__init__()
|
||||
self._order.insert(0, ('code', 'ASC'))
|
||||
|
||||
def default_active(self, cursor, user, context=None):
|
||||
return True
|
||||
|
||||
def default_rounding(self, cursor, user, context=None):
|
||||
return 0.01
|
||||
|
||||
def default_digits(self, cursor, user, context=None):
|
||||
return 2
|
||||
|
||||
def name_search(self, cursor, user, name, args=None, operator='ilike',
|
||||
context=None, limit=None):
|
||||
if args is None:
|
||||
args = []
|
||||
args_name = args[:]
|
||||
args_code = args[:]
|
||||
if name:
|
||||
args_name += [(self._rec_name, operator, name)]
|
||||
args_code += [('code', operator, name)]
|
||||
ids = self.search(cursor, user, args_code, limit=limit, context=context)
|
||||
if len(ids) != 1:
|
||||
ids += self.search(cursor, user, args_name, limit=limit,
|
||||
context=context)
|
||||
res = self.name_get(cursor, user, ids, context=context)
|
||||
return res
|
||||
|
||||
def get_rate(self, cursor, user, ids, name, arg, context=None):
|
||||
'''
|
||||
Return the rate at the date from the context or the current date
|
||||
'''
|
||||
res = {}
|
||||
rate_obj = self.pool.get('account.currency.rate')
|
||||
if context is None:
|
||||
context = {}
|
||||
date = context.get('date', time.strftime('%Y-%m-%d'))
|
||||
for currency_id in ids:
|
||||
rate_ids = rate_obj.search(cursor, user, [
|
||||
('currency', '=', currency_id),
|
||||
('date', '<=', date),
|
||||
], limit=1, order=[('date', 'DESC')])
|
||||
if rate_ids:
|
||||
res[currency_id] = rate_ids[0]
|
||||
else:
|
||||
res[currency_id] = 0.0
|
||||
rate_ids = [x for x in res.values() if x]
|
||||
rates = rate_obj.browse(cursor, user, rate_ids, context=context)
|
||||
id2rate = {}
|
||||
for rate in rates:
|
||||
id2rate[rate.id] = rate
|
||||
for currency_id in res.keys():
|
||||
if res[currency_id]:
|
||||
res[currency_id] = id2rate[res[currency_id]].rate
|
||||
return res
|
||||
|
||||
def round(self, cursor, user, currency, amount):
|
||||
'Round the amount depending of the currency'
|
||||
return (amount / currency.rounding).quantize(Decimal('1.')) * currency.rounding
|
||||
|
||||
def is_zero(self, cursor, user, currency, amount):
|
||||
'Return True if the amount can be considered as zero for the currency'
|
||||
return abs(self.round(cursor, user, currency, amount)) < currency.rounding
|
||||
|
||||
def compute(self, cursor, user, from_currency, amount, to_currency,
|
||||
round=True, context=None):
|
||||
'''
|
||||
Take a currency and an amount
|
||||
Return the amount to the new currency
|
||||
Use the rate of the date of the context or the current date
|
||||
'''
|
||||
if isinstance(from_currency, (int, long)):
|
||||
from_currency = self.browse(cursor, user, from_currency, context=context)
|
||||
if isinstance(to_currency, (int, long)):
|
||||
to_currency = self.browse(cursor, user, to_currency, context=context)
|
||||
if (not from_currency.rate) or (not to_currency.rate):
|
||||
date = context.get('date', time.strftime('%Y-%m-%d'))
|
||||
if not from_currency.rate:
|
||||
name = from_currency.name
|
||||
else:
|
||||
name = to_currency.name
|
||||
raise ExceptOSV('UserError', 'No rate found \n' \
|
||||
'for the currency: %s \n' \
|
||||
'at the date: %s' % (name, date))
|
||||
if to_currency == from_currency:
|
||||
if round:
|
||||
return self.round(cursor, user, to_currency, amount)
|
||||
else:
|
||||
return amount
|
||||
else:
|
||||
if round:
|
||||
return self.round(cursor, user, to_currency,
|
||||
amount * to_currency.rate / from_currency.rate)
|
||||
else:
|
||||
return amount * to_currency.rate / from_currency.rate
|
||||
|
||||
Currency()
|
||||
|
||||
|
||||
class Rate(OSV):
|
||||
'Rate'
|
||||
_name = 'account.currency.rate'
|
||||
_description = __doc__
|
||||
_rec_name = 'date'
|
||||
date = fields.Date('Date', required=True, select=1)
|
||||
rate = fields.Numeric('Rate', digits=(12, 6), required=1)
|
||||
currency = fields.Many2One('account.currency', 'Currency')
|
||||
|
||||
def __init__(self):
|
||||
super(Rate, self).__init__()
|
||||
self._sql_constraints = [
|
||||
('date_currency_uniq', 'UNIQUE(date, currency)',
|
||||
'A currency can only have one rate by date!'),
|
||||
]
|
||||
self._order.insert(0, ('date', 'DESC'))
|
||||
|
||||
def default_date(self, cursor, user, context=None):
|
||||
return datetime.date.today()
|
||||
|
||||
Rate()
|
||||
|
||||
|
||||
class Company(OSV):
|
||||
_name = 'company.company'
|
||||
currency = fields.Many2One('account.currency', 'Currency', required=True)
|
||||
|
||||
Company()
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="currency_view_form">
|
||||
<field name="model">account.currency</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Currency" col="6">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="code"/>
|
||||
<field name="code"/>
|
||||
<label name="active"/>
|
||||
<field name="active" xexpand="0" width="100"/>
|
||||
<label name="rounding"/>
|
||||
<field name="rounding"/>
|
||||
<label name="digits"/>
|
||||
<field name="digits"/>
|
||||
<newline/>
|
||||
<label name="rate"/>
|
||||
<field name="rate"/>
|
||||
<field name="rates" colspan="6" mode="tree,form,graph">
|
||||
<tree string="Rates">
|
||||
<field name="date"/>
|
||||
<field name="rate"/>
|
||||
</tree>
|
||||
<form string="Rate">
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
<label name="rate"/>
|
||||
<field name="rate"/>
|
||||
</form>
|
||||
<graph string="Rates" type="line">
|
||||
<x>
|
||||
<field name="date"/>
|
||||
</x>
|
||||
<y>
|
||||
<field name="rate" fill="1" empty="0"/>
|
||||
</y>
|
||||
</graph>
|
||||
</field>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="currency_view_tree">
|
||||
<field name="model">account.currency</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Currencies">
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="rate"/>
|
||||
<field name="active" tree_invisible="1" select="2"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window" id="act_currency_form">
|
||||
<field name="name">Currencies</field>
|
||||
<field name="res_model">account.currency</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_currency_form_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="currency_view_tree"/>
|
||||
<field name="act_window" ref="act_currency_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_currency_form_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="currency_view_form"/>
|
||||
<field name="act_window" ref="act_currency_form"/>
|
||||
</record>
|
||||
<menuitem parent="menu_account_configuration" action="act_currency_form"
|
||||
id="menu_currency_form"/>
|
||||
<record model="ir.model.access" id="access_currency">
|
||||
<field name="model" search="[('model', '=', 'account.currency')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_unlink" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_currency_account_admin">
|
||||
<field name="model" search="[('model', '=', 'account.currency')]"/>
|
||||
<field name="group" ref="group_account_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_unlink" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="company_view_form">
|
||||
<field name="model">company.company</field>
|
||||
<field name="inherit" ref="company.company_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/field[@name="parent"]"
|
||||
position="after">
|
||||
<label name="currency"/>
|
||||
<field name="currency"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="company_view_tree">
|
||||
<field name="model">company.company</field>
|
||||
<field name="inherit" ref="company.company_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath
|
||||
expr="/tree/field[@name="partner"]"
|
||||
position="after">
|
||||
<field name="currency" select="1"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_currency_rate">
|
||||
<field name="model" search="[('model', '=', 'account.currency.rate')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_unlink" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_currency_rate_account_admin">
|
||||
<field name="model" search="[('model', '=', 'account.currency.rate')]"/>
|
||||
<field name="group" ref="group_account_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_unlink" eval="True"/>
|
||||
</record>
|
||||
<record model="account.currency" id="eur">
|
||||
<field name="name">Euro</field>
|
||||
<field name="code">EUR</field>
|
||||
<field name="rounding" eval="0.01"/>
|
||||
<field name="digits" eval="2"/>
|
||||
</record>
|
||||
<record model="account.currency.rate" id="eur_rate">
|
||||
<field name="date" eval="time.strftime('%Y-01-01')"/>
|
||||
<field name="rate" eval="1.0"/>
|
||||
<field name="currency" ref="eur"/>
|
||||
</record>
|
||||
<record model="account.currency" id="usd">
|
||||
<field name="name">United States dollar</field>
|
||||
<field name="code">USD</field>
|
||||
<field name="rounding" eval="0.01"/>
|
||||
<field name="digits" eval="2"/>
|
||||
</record>
|
||||
<record model="account.currency" id="chf">
|
||||
<field name="name">Swiss franc</field>
|
||||
<field name="code">CHF</field>
|
||||
<field name="rounding" eval="0.01"/>
|
||||
<field name="digits" eval="2"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+1
-1
@@ -210,7 +210,7 @@ class CloseFiscalYear(Wizard):
|
||||
'''
|
||||
Method to override to implement new close method
|
||||
'''
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
fiscalyear_obj = self.pool.get('account.fiscalyear')
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class Move(OSV):
|
||||
'''
|
||||
Validate balanced move and centralise it if in centralised journal
|
||||
'''
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
@@ -219,7 +219,7 @@ class Move(OSV):
|
||||
return
|
||||
|
||||
def post(self, cursor, user, ids, context=None):
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
sequence_obj = self.pool.get('ir.sequence')
|
||||
|
||||
if isinstance(ids, (int, long)):
|
||||
@@ -301,7 +301,7 @@ class Reconciliation(OSV):
|
||||
raise ExceptORM('UserError', 'You can not modify a reconciliation!')
|
||||
|
||||
def check_lines(self, cursor, user, ids):
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
for reconciliation in self.browse(cursor, user, ids):
|
||||
amount = Decimal('0.0')
|
||||
account = None
|
||||
@@ -354,7 +354,7 @@ class Line(OSV):
|
||||
reference = fields.char('Reference', size=None)
|
||||
amount_second_currency = fields.Numeric('Amount Second Currency',
|
||||
digits=(16, 2), help='The amount expressed in a second currency')
|
||||
second_currency = fields.Many2One('account.currency', 'Second Currency',
|
||||
second_currency = fields.Many2One('currency.currency', 'Second Currency',
|
||||
help='The second currency')
|
||||
partner = fields.Many2One('partner.partner', 'Partner',
|
||||
on_change=['move', 'partner', 'account', 'debit', 'credit',
|
||||
@@ -665,7 +665,7 @@ class Line(OSV):
|
||||
partner_obj = self.pool.get('partner.partner')
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
account_obj = self.pool.get('account.account')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
res = {}
|
||||
if (not vals.get('partner')) or vals.get('account'):
|
||||
return res
|
||||
@@ -1072,7 +1072,7 @@ class Line(OSV):
|
||||
def reconcile(self, cursor, user, ids, journal_id=False, date=False,
|
||||
account_id=False, context=None):
|
||||
move_obj = self.pool.get('account.move')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
reconciliation_obj = self.pool.get('account.move.reconciliation')
|
||||
period_obj = self.pool.get('account.period')
|
||||
|
||||
@@ -1335,7 +1335,7 @@ class ReconcileLines(Wizard):
|
||||
|
||||
def _check_writeoff(self, cursor, user, data, context=None):
|
||||
line_obj = self.pool.get('account.move.line')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
|
||||
company = None
|
||||
amount = Decimal('0.0')
|
||||
|
||||
@@ -56,7 +56,7 @@ class Code(OSV):
|
||||
def get_sum(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
currency_obj = self.pool.get('account.currency')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
|
||||
child_ids = self.search(cursor, user, [('parent', 'child_of', ids)],
|
||||
context=context)
|
||||
|
||||
Reference in new issue
Block a user