[IMP] product/uom: renamed field uom_factor to uom_type and 'default' to 'reference' before it's too late + improved example data, help and form view
bzr revid: odo@openerp.com-20100707234419-9jkwunfiueb0q3zd
This commit is contained in:
parent
c36c45c63f
commit
edbc5516be
|
@ -71,33 +71,34 @@ class product_uom(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True, translate=True),
|
||||
'category_id': fields.many2one('product.uom.categ', 'UoM Category', required=True, ondelete='cascade',
|
||||
help="Unit of Measure of a category can be converted between each others in the same category."),
|
||||
help="Quantity conversions may happen automatically between Units of Measure in the same category, according to their respective ratios."),
|
||||
'factor': fields.float('Ratio', digits=(12, 6), required=True,
|
||||
help='The coefficient for the formula:\n' \
|
||||
'1 (base unit) = coeff (this unit). Ratio = 1 / Factor.'),
|
||||
help='How many times this UoM is smaller than the reference UoM in this category:\n'\
|
||||
'1 * (reference unit) = ratio * (this unit)'),
|
||||
'factor_inv': fields.function(_factor_inv, digits=(12, 6),
|
||||
fnct_inv=_factor_inv_write,
|
||||
method=True, string='Ratio',
|
||||
help='The coefficient for the formula:\n' \
|
||||
'coeff (base unit) = 1 (this unit). Factor = 1 / Rate.'),
|
||||
help='How many times this UoM is bigger than the reference UoM in this category:\n'\
|
||||
'1 * (this unit) = ratio * (reference unit)', required=True),
|
||||
'rounding': fields.float('Rounding Precision', digits=(16, 3), required=True,
|
||||
help="The computed quantity will be a multiple of this value. Use 1.0 for products that can not be split."),
|
||||
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the unit of measure without removing it."),
|
||||
'uom_factor': fields.selection([('bigger','Bigger than the default'),
|
||||
('smaller','Smaller than the default'),
|
||||
('default','Default UoM for the category')],'Type of Unit', required=1),
|
||||
help="The computed quantity will be a multiple of this value. "\
|
||||
"Use 1.0 for a UoM that cannot be further split, such as a piece."),
|
||||
'active': fields.boolean('Active', help="By unchecking the active field you can disable a unit of measure without deleting it."),
|
||||
'uom_type': fields.selection([('bigger','Bigger than the reference UoM'),
|
||||
('reference','Reference UoM for this category (ratio=1)'),
|
||||
('smaller','Smaller than the reference UoM')],'UoM Type', required=1),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'factor': lambda *a: 1.0,
|
||||
'factor_inv': lambda *a: 1.0,
|
||||
'active': lambda *a: 1,
|
||||
'rounding': lambda *a: 0.01,
|
||||
'uom_factor': lambda *a: 'default',
|
||||
'factor': 1.0,
|
||||
'factor_inv': 1.0,
|
||||
'active': 1,
|
||||
'rounding': 0.01,
|
||||
'uom_type': 'reference',
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
('factor_gt_zero', 'CHECK (factor!=0)', 'Value of the factor can never be 0 !'),
|
||||
('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!'),
|
||||
]
|
||||
|
||||
def _compute_qty(self, cr, uid, from_uom_id, qty, to_uom_id=False):
|
||||
|
@ -133,8 +134,8 @@ class product_uom(osv.osv):
|
|||
amount = amount / to_unit.factor
|
||||
return amount
|
||||
|
||||
def onchange_factor(self, cursor, user, ids, value):
|
||||
if value == 'default':
|
||||
def onchange_type(self, cursor, user, ids, value):
|
||||
if value == 'reference':
|
||||
return {'value': {'factor': 1, 'factor_inv': 1}}
|
||||
return {}
|
||||
|
||||
|
|
|
@ -24,38 +24,55 @@
|
|||
<record id="product_uom_unit" model="product.uom">
|
||||
<field name="category_id" ref="product_uom_categ_unit"/>
|
||||
<field name="name">PCE</field>
|
||||
<field name="factor">1.0</field>
|
||||
<field name="rounding">1.0</field>
|
||||
<field name="factor" eval="1.0"/>
|
||||
<field name="rounding" eval="1.0"/>
|
||||
</record>
|
||||
<record id="product_uom_kgm" model="product.uom">
|
||||
<field name="category_id" ref="product_uom_categ_kgm"/>
|
||||
<field name="name">KGM</field>
|
||||
<field name="factor">1</field>
|
||||
<field name="name">kg</field>
|
||||
<field name="factor" eval="1"/>
|
||||
</record>
|
||||
<record id="product_uom_gram" model="product.uom">
|
||||
<field name="category_id" ref="product_uom_categ_kgm"/>
|
||||
<field name="name">g</field>
|
||||
<field name="factor" eval="1000"/>
|
||||
<field name="uom_type">smaller</field>
|
||||
</record>
|
||||
<record id="uom_hour" model="product.uom">
|
||||
<field name="name">Hour</field>
|
||||
<field name="name">hour</field>
|
||||
<field eval="uom_categ_wtime" name="category_id"/>
|
||||
<field name="factor">8.0</field>
|
||||
<field name="factor" eval="8.0"/>
|
||||
<field name="uom_type">smaller</field>
|
||||
</record>
|
||||
<record id="uom_day" model="product.uom">
|
||||
<field name="name">Day</field>
|
||||
<field name="name">day</field>
|
||||
<field eval="uom_categ_wtime" name="category_id"/>
|
||||
<field name="factor">1.0</field>
|
||||
<field name="factor" eval="1.0"/>
|
||||
</record>
|
||||
<record id="product_uom_ton" model="product.uom">
|
||||
<field name="category_id" ref="product_uom_categ_kgm"/>
|
||||
<field name="name">TON</field>
|
||||
<field name="factor">0.001</field>
|
||||
<!-- 'tonne' is the most common spelling in english-speaking countries,
|
||||
the alternative is 'metric ton' in the US, abbreviated as 'mt' -->
|
||||
<field name="name">tonne</field>
|
||||
<field name="factor" eval="0.001"/>
|
||||
<field name="uom_type">bigger</field>
|
||||
</record>
|
||||
<record id="product_uom_meter" model="product.uom">
|
||||
<field name="category_id" ref="uom_categ_length"/>
|
||||
<field name="name">Meter</field>
|
||||
<field name="factor">1.0</field>
|
||||
<field name="name">m</field>
|
||||
<field name="factor" eval="1.0"/>
|
||||
</record>
|
||||
<record id="product_uom_km" model="product.uom">
|
||||
<field name="category_id" ref="uom_categ_length"/>
|
||||
<field name="name">Kilometer</field>
|
||||
<field name="factor">0.001</field>
|
||||
<field name="name">km</field>
|
||||
<field name="factor" eval="0.001"/>
|
||||
<field name="uom_type">bigger</field>
|
||||
</record>
|
||||
<record id="product_uom_cm" model="product.uom">
|
||||
<field name="category_id" ref="uom_categ_length"/>
|
||||
<field name="name">cm</field>
|
||||
<field name="factor" eval="100"/>
|
||||
<field name="uom_type">smaller</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
|
|
@ -310,16 +310,29 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Units of Measure">
|
||||
<group col="6" colspan="4">
|
||||
<field name="name" select="1"/>
|
||||
<field name="category_id" select="1" widget="selection"/>
|
||||
<field name="active"/>
|
||||
<field name="uom_factor" on_change="onchange_factor(uom_factor)"/>
|
||||
<group colspan="2" col="2">
|
||||
<field name="factor" attrs="{'invisible':[('uom_factor','<>','smaller')]}"/>
|
||||
<field name="factor_inv" string="Factor Data" attrs="{'invisible':[('uom_factor','<>','bigger')]}"/>
|
||||
<group col="2" colspan="2">
|
||||
<separator string="Unit of Measure Properties" colspan="4"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="category_id" select="1" widget="selection"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
<group col="4" colspan="4">
|
||||
<separator string="Ratio & Precision" colspan="4"/>
|
||||
<group colspan="2" col="2">
|
||||
<field name="uom_type" on_change="onchange_type(uom_type)"/>
|
||||
<field name="rounding"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<group col="2" colspan="2" attrs="{'invisible':[('uom_type','!=','smaller')]}">
|
||||
<field name="factor"/>
|
||||
<label colspan="2" string=" e.g: 1 * (reference unit) = ratio * (this unit)"/>
|
||||
</group>
|
||||
<group col="2" colspan="2" attrs="{'invisible':[('uom_type','!=','bigger')]}">
|
||||
<field name="factor_inv"/>
|
||||
<label colspan="2" string=" e.g: 1 * (this unit) = ratio * (reference unit)"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="rounding"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
|
Loading…
Reference in New Issue