'active': fields.boolean('Active'),
'company_id':fields.many2one('res.company', 'Company'),
'date': fields.date('Date'),
- 'base': fields.boolean('Base')
-
+ 'base': fields.boolean('Base'),
- 'position_on_report': fields.selection([('after','After Amount'),('before','Before Amount')], 'Symbol position in reports', help="Determines where the currency symbol is printed within reports, after or before the amount.")
++ 'position': fields.selection([('after','After Amount'),('before','Before Amount')], 'Symbol position', help="Determines where the currency symbol should be placed after or before the amount.")
}
_defaults = {
'active': lambda *a: 1,
- 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'res.currency', context=c),
- 'position_on_report' : 'after',
++ 'position' : 'after',
}
+ _sql_constraints = [
+ # this constraint does not cover all cases due to SQL NULL handling for company_id,
+ # so it is complemented with a unique index (see below). The constraint and index
+ # share the same prefix so that IntegrityError triggered by the index will be caught
+ # and reported to the user with the constraint's error message.
+ ('unique_name_company_id', 'unique (name, company_id)', 'The currency code must be unique per company!'),
+ ]
_order = "name"
+ def init(self, cr):
+ # CONSTRAINT/UNIQUE INDEX on (name,company_id)
+ # /!\ The unique constraint 'unique_name_company_id' is not sufficient, because SQL92
+ # only support field names in constraint definitions, and we need a function here:
+ # we need to special-case company_id to treat all NULL company_id as equal, otherwise
+ # we would allow duplicate "global" currencies (all having company_id == NULL)
+ cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'res_currency_unique_name_company_id_idx'""")
+ if not cr.fetchone():
+ cr.execute("""CREATE UNIQUE INDEX res_currency_unique_name_company_id_idx
+ ON res_currency
+ (name, (COALESCE(company_id,-1)))""")
+
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')
<field name="rate"/>
<field name="rounding"/>
<field name="accuracy"/>
++ <field name="position"/>
<field name="active"/>
</tree>
</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Currency">
-- <group col="6" colspan="6">
- <field name="name" select="1"/>
++ <group col="6" colspan="4">
+ <field name="name"/>
<field name="rate"/>
- <field name="company_id" select="2" groups="base.group_multi_company" />
- <field name="symbol"/>
+ <field name="company_id" groups="base.group_multi_company"/>
- <field name="symbol"/>
</group>
-- <group col="2" colspan="2">
-- <separator string="Price Accuracy" colspan="2"/>
-- <field name="rounding"/>
-- <field name="accuracy"/>
-- </group>
++ <group col="6" colspan="4">
++ <group col="2" colspan="2">
++ <separator string="Price Accuracy" colspan="2"/>
++ <field name="rounding"/>
++ <field name="accuracy"/>
++ </group>
++
++ <group col="2" colspan="2">
++ <separator string="Display" colspan="2"/>
++ <field name="symbol"/>
++ <field name="position"/>
++ </group>
-- <group col="2" colspan="2">
-- <separator string="Miscelleanous" colspan="2"/>
-- <field name="base"/>
-- <field name="active" select="1"/>
- <field name="position_on_report" />
++ <group col="2" colspan="2">
++ <separator string="Miscelleanous" colspan="2"/>
++ <field name="base"/>
++ <field name="active" select="1"/>
++ </group>
</group>
<field colspan="4" mode="tree,form" name="rate_ids" nolabel="1" attrs="{'readonly':[('base','=',True)]}">
date = datetime(*value.timetuple()[:6])
return date.strftime(date_format)
- return self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
+ res = self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
- res = currency_obj and currency_obj.position_on_report and (currency_obj.position_on_report == 'after' and '%s %s'%(res,currency_obj.symbol) or '%s %s'%(currency_obj.symbol, res) ) or res
++ if currency_obj:
++ if currency_obj.position == 'after':
++ res='%s %s'%(res,currency_obj.symbol)
++ elif currency_obj and currency_obj.position == 'before':
++ res='%s %s'%(currency_obj.symbol, res)
+ return res
def repeatIn(self, lst, name,nodes_parent=False):
ret_lst = []