Ujjvala Collins (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/trunk-currency_rate_type-mra into 
lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-currency_rate_type-mra/+merge/72143

[ADD] base:
---------------------
 * Added a new object res.currency.rate.type for a new module called 
account_currency_provisioning in addons.
 * In res.currency.rate object, added a new field m2o res.currency.rate.type 
(new object with only name) with widget = selection, not required.
 * In that object, change the compute method in order to allow to receive an 
extra argument: type of currency rate (by default=False) and select the rate 
accordingly.
 * Define menu for currency rate type.
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-currency_rate_type-mra/+merge/72143
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-currency_rate_type-mra.
=== modified file 'openerp/addons/base/res/res_currency.py'
--- openerp/addons/base/res/res_currency.py	2011-07-19 11:36:30 +0000
+++ openerp/addons/base/res/res_currency.py	2011-08-19 07:02:16 +0000
@@ -28,22 +28,28 @@
 
 class res_currency(osv.osv):
     def _current_rate(self, cr, uid, ids, name, arg, context=None):
-        if context is None:
-            context = {}
+        currency_rate_obj = self.pool.get('res.currency.rate')
         res = {}
+        if context is None:
+            context = {}
         if 'date' in context:
             date = context['date']
         else:
             date = time.strftime('%Y-%m-%d')
-        date = date or time.strftime('%Y-%m-%d')
+        domain = [('currency_id', 'in', ids), ('name', '<=', date)]
+        currency_rate_type_id = context.get('currency_rate_type_id', False)
+        if currency_rate_type_id:
+            domain.append(('currency_rate_type_id', '=', currency_rate_type_id))
+        curr_rate_ids = currency_rate_obj.search(cr, uid, domain, order='name desc', context=context)
+        curr_rates = currency_rate_obj.browse(cr, uid, curr_rate_ids, context=context)
         for id in ids:
-            cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %s AND name <= %s ORDER BY name desc LIMIT 1" ,(id, date))
-            if cr.rowcount:
-                id, rate = cr.fetchall()[0]
-                res[id] = rate
-            else:
-                res[id] = 0
+            res[id] = 0
+            for cur in curr_rates:
+                if cur.currency_id.id == id:
+                    res[id] = cur.rate
+                    break
         return res
+
     _name = "res.currency"
     _description = "Currency"
     _columns = {
@@ -68,13 +74,13 @@
     _order = "name"
 
     def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
-        res=super(osv.osv, self).read(cr, user, ids, fields, context, load)
+        currency_rate_obj=  self.pool.get('res.currency.rate')
+        res = super(osv.osv, self).read(cr, user, ids, fields, context, load)
         for r in res:
             if r.__contains__('rate_ids'):
                 rates=r['rate_ids']
                 if rates:
-                    currency_rate_obj=  self.pool.get('res.currency.rate')
-                    currency_date = currency_rate_obj.read(cr,user,rates[0],['name'])['name']
+                    currency_date = currency_rate_obj.read(cr, user, rates[0], ['name'])['name']
                     r['date'] = currency_date
         return res
 
@@ -109,13 +115,17 @@
             raise osv.except_osv(_('Error'), _('No rate found \n' \
                     'for the currency: %s \n' \
                     'at the date: %s') % (currency_symbol, date))
+
         return to_currency.rate/from_currency.rate
 
-    def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context=None):
+    def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, rate_type=False, context=None):
         if not from_currency_id:
             from_currency_id = to_currency_id
         if not to_currency_id:
             to_currency_id = from_currency_id
+
+        if rate_type:
+            context.update({'currency_rate_type_id': rate_type})
         xc = self.browse(cr, uid, [from_currency_id,to_currency_id], context=context)
         from_currency = (xc[0].id == from_currency_id and xc[0]) or xc[1]
         to_currency = (xc[0].id == to_currency_id and xc[0]) or xc[1]
@@ -133,6 +143,15 @@
 
 res_currency()
 
+class res_currency_rate_type(osv.osv):
+    _name = "res.currency.rate.type"
+    _description = "Currency Rate Type"
+    _columns = {
+        'name': fields.char('Name', size=32, required=True),
+    }
+
+res_currency_rate_type()
+
 class res_currency_rate(osv.osv):
     _name = "res.currency.rate"
     _description = "Currency Rate"
@@ -141,11 +160,13 @@
         'rate': fields.float('Rate', digits=(12,6), required=True,
             help='The rate of the currency to the currency of rate 1'),
         'currency_id': fields.many2one('res.currency', 'Currency', readonly=True),
+        'currency_rate_type_id': fields.many2one('res.currency.rate.type', 'Currency Rate Type'),
     }
     _defaults = {
         'name': lambda *a: time.strftime('%Y-%m-%d'),
     }
     _order = "name desc"
+
 res_currency_rate()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'openerp/addons/base/res/res_currency_view.xml'
--- openerp/addons/base/res/res_currency_view.xml	2010-11-18 11:11:54 +0000
+++ openerp/addons/base/res/res_currency_view.xml	2011-08-19 07:02:16 +0000
@@ -48,6 +48,7 @@
                         <form string="Rates">
                             <field name="name"/>
                             <field name="rate"/>
+                            <field name="currency_rate_type_id" widget="selection"/>
                         </form>
                         <tree string="Rates">
                             <field name="name"/>
@@ -66,5 +67,28 @@
 
         <menuitem action="action_currency_form" id="menu_action_currency_form" parent="menu_localisation" sequence="3"/>
 
+        <!-- 
+            Currency Rate Type
+        -->
+        <record id="view_currency_rate_type_form" model="ir.ui.view">
+            <field name="name">res.currency.rate.type.form</field>
+            <field name="model">res.currency.rate.type</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form string="Currency Rate Type">
+                    <field name="name"/>
+                </form>
+            </field>
+        </record>
+
+        <record id="action_currency_rate_type_form" model="ir.actions.act_window">
+            <field name="name">Currency Rate Type</field>
+            <field name="res_model">res.currency.rate.type</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+        </record>
+        
+        <menuitem action="action_currency_rate_type_form" id="menu_action_currency_rate_type_form" parent="menu_localisation" sequence="7"/>
+
     </data>
 </openerp>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to