commit
bfba3deb93
|
@ -106,11 +106,21 @@ class product_uom(osv.osv):
|
|||
data['factor'] = self._compute_factor_inv(data['factor_inv'])
|
||||
del(data['factor_inv'])
|
||||
return super(product_uom, self).create(cr, uid, data, context)
|
||||
|
||||
def _reference_uom(self, cr, uid, ids, field, arg, context=None):
|
||||
res = {}
|
||||
for uom in self.browse(cr, uid, ids, context):
|
||||
uom_ids = []
|
||||
if uom.category_id and uom.category_id.id:
|
||||
uom_ids = self.search(cr, uid, [('category_id', '=', uom.category_id.id), ('uom_type', '=', 'reference')], context=context)
|
||||
if uom_ids:
|
||||
res[uom.id] = uom_ids[0]
|
||||
return res
|
||||
|
||||
_order = "name"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True, translate=True),
|
||||
'category_id': fields.many2one('product.uom.categ', 'Unit of Measure Category', required=True, ondelete='cascade',
|
||||
'name': fields.char('Unit of Measure', size=64, required=True, translate=True),
|
||||
'category_id': fields.many2one('product.uom.categ', 'Category', required=True, ondelete='cascade',
|
||||
help="Quantity conversions may happen automatically between Units of Measure in the same category, according to their respective ratios."),
|
||||
'factor': fields.float('Ratio', required=True,digits=(12, 12),
|
||||
help='How many times this Unit of Measure is smaller than the reference Unit of Measure in this category:\n'\
|
||||
|
@ -120,13 +130,14 @@ class product_uom(osv.osv):
|
|||
string='Ratio',
|
||||
help='How many times this Unit of Measure is bigger than the reference Unit of Measure in this category:\n'\
|
||||
'1 * (this unit) = ratio * (reference unit)', required=True),
|
||||
'rounding': fields.float('Rounding Precision', digits_compute=dp.get_precision('Product Unit of Measure'), required=True,
|
||||
'rounding': fields.float('Rounding precision', digits_compute=dp.get_precision('Product Unit of Measure'), required=True,
|
||||
help="The computed quantity will be a multiple of this value. "\
|
||||
"Use 1.0 for a Unit of Measure 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 Unit of Measure'),
|
||||
('reference','Reference Unit of Measure for this category'),
|
||||
('smaller','Smaller than the reference Unit of Measure')],'Unit of Measure Type', required=1),
|
||||
('smaller','Smaller than the reference Unit of Measure')],'Type', required=1),
|
||||
'reference_uom_id': fields.function(_reference_uom, type='many2one', relation="product.uom"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -139,6 +150,14 @@ class product_uom(osv.osv):
|
|||
('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!')
|
||||
]
|
||||
|
||||
def onchange_category_id(self, cr, uid, ids, category_id):
|
||||
reference_uom = False
|
||||
if category_id:
|
||||
uom_ids = self.search(cr, uid, [('category_id', '=',category_id),('uom_type', '=', 'reference')])
|
||||
if uom_ids:
|
||||
reference_uom = uom_ids[0]
|
||||
return {'value':{'reference_uom_id': reference_uom}}
|
||||
|
||||
def _compute_qty(self, cr, uid, from_uom_id, qty, to_uom_id=False):
|
||||
if not from_uom_id or not qty or not to_uom_id:
|
||||
return qty
|
||||
|
|
|
@ -412,7 +412,6 @@
|
|||
<tree string="Units of Measure">
|
||||
<field name="name"/>
|
||||
<field name="category_id"/>
|
||||
<field name="factor"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -425,20 +424,23 @@
|
|||
<group>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="category_id"/>
|
||||
<field name="category_id" on_change="onchange_category_id(category_id)"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="uom_type" on_change="onchange_type(uom_type)"/>
|
||||
<p attrs="{'invisible':[('uom_type','!=','smaller')]}" colspan="2">
|
||||
e.g: 1 * (reference unit) = ratio * (this unit)
|
||||
</p>
|
||||
<p attrs="{'invisible':[('uom_type','!=','bigger')]}" colspan="2">
|
||||
e.g: 1 * (this unit) = ratio * (reference unit)
|
||||
</p>
|
||||
<label string="Computation" for="factor" attrs="{'invisible':[('uom_type','=','reference')]}" style="margin: 9px 0 9px 0;"/>
|
||||
<group col="5" attrs="{'invisible':[('uom_type','=','reference')]}">
|
||||
<div style="margin-left: -12px;">
|
||||
<field name="factor_inv" class="oe_inline" attrs="{'invisible':[('uom_type','!=','bigger')]}" String="Computation" nolabel="1"/>
|
||||
<label string="1" attrs="{'invisible':[('uom_type','!=','smaller')]}"/>
|
||||
<field class="oe_inline" name="reference_uom_id" attrs="{'invisible':[('uom_type','=','reference')]}" nolabel="1"/>
|
||||
<label string="="/>
|
||||
<field class="oe_inline" name="factor" attrs="{'invisible':[('uom_type','!=','smaller')]}" String="Computation" nolabel="1"/>
|
||||
<label string="1" attrs="{'invisible':[('uom_type','!=','bigger')]}"/>
|
||||
</div>
|
||||
</group>
|
||||
<field name="rounding"/>
|
||||
<field name="factor" attrs="{'invisible':[('uom_type','!=','smaller')]}"/>
|
||||
<field name="factor_inv" attrs="{'invisible':[('uom_type','!=','bigger')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue