Add unit_digits on purchase line and use it for quantity
This commit is contained in:
1 parent
81f6bf790d
commit
45ba03682c
3 files changed
+23
No files matched your search
Binary file not shown.
+20
@@ -534,6 +534,7 @@ class PurchaseLine(OSV):
|
||||
('title', 'Title'),
|
||||
], 'Type', select=1, required=True)
|
||||
quantity = fields.Float('Quantity',
|
||||
digits="(16, unit_digits)",
|
||||
states={
|
||||
'invisible': "type != 'line'",
|
||||
'required': "type == 'line'",
|
||||
@@ -543,6 +544,8 @@ class PurchaseLine(OSV):
|
||||
'required': "product",
|
||||
'invisible': "type != 'line'",
|
||||
}, domain="[('category', '=', (product, 'product'))]")
|
||||
unit_digits = fields.Function('get_unit_digits', type='integer',
|
||||
string='Unit Digits', on_change_with=['unit'])
|
||||
product = fields.Many2One('product.product', 'Product',
|
||||
domain=[('purchasable', '=', True)],
|
||||
states={
|
||||
@@ -639,6 +642,22 @@ class PurchaseLine(OSV):
|
||||
res[line.id] = val
|
||||
return res
|
||||
|
||||
def on_change_with_unit_digits(self, cursor, user, ids, vals,
|
||||
context=None):
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
if vals.get('unit'):
|
||||
uom = uom_obj.browse(cursor, user, vals['unit'],
|
||||
context=context)
|
||||
return uom.digits
|
||||
return 2
|
||||
|
||||
def get_unit_digits(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for line in self.browse(cursor, user, ids, context=context):
|
||||
if line.unit:
|
||||
res[line.id] = line.unit.digits
|
||||
return res
|
||||
|
||||
def on_change_product(self, cursor, user, ids, vals, context=None):
|
||||
party_obj = self.pool.get('relationship.party')
|
||||
product_obj = self.pool.get('product.product')
|
||||
@@ -688,6 +707,7 @@ class PurchaseLine(OSV):
|
||||
or vals.get('unit') not in [x.id for x in category.uoms]:
|
||||
res['unit'] = uom_obj.name_get(cursor, user, product.default_uom.id,
|
||||
context=context)[0]
|
||||
res['unit_digits'] = product.default_uom.digits
|
||||
return res
|
||||
|
||||
def on_change_with_amount(self, cursor, user, ids, vals, context=None):
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
<field name="taxes"/>
|
||||
<field name="amount"/>
|
||||
<field name="sequence" tree_invisible="1"/>
|
||||
<field name="unit_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<group col="2" colspan="2">
|
||||
@@ -568,6 +569,7 @@
|
||||
<field name="taxes" colspan="4"/>
|
||||
<separator name="comment" colspan="4"/>
|
||||
<field name="comment" colspan="4"/>
|
||||
<field name="unit_digits" invisible="1"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
@@ -588,6 +590,7 @@
|
||||
<field name="unit_price" select="2"/>
|
||||
<field name="taxes"/>
|
||||
<field name="amount"/>
|
||||
<field name="unit_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
|
||||
Reference in new issue
Block a user