Remove special uom search clause
review294001
This commit is contained in:
1 parent
5106604618
commit
3f9ddfa095
3 files changed
+18
-56
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Remove special uom search clause
|
||||
* New product types: Goods, Assets and Service
|
||||
* Category is no more required on product
|
||||
|
||||
|
||||
+17
@@ -47,6 +47,10 @@ class Template(ModelSQL, ModelView):
|
||||
depends=DEPENDS))
|
||||
default_uom = fields.Many2One('product.uom', 'Default UOM', required=True,
|
||||
states=STATES, depends=DEPENDS)
|
||||
default_uom_category = fields.Function(
|
||||
fields.Many2One('product.uom.category', 'Default UOM Category',
|
||||
on_change_with=['default_uom']),
|
||||
'get_default_uom_category')
|
||||
active = fields.Boolean('Active', select=True)
|
||||
products = fields.One2Many('product.product', 'template', 'Products',
|
||||
states=STATES, depends=DEPENDS)
|
||||
@@ -76,6 +80,19 @@ class Template(ModelSQL, ModelView):
|
||||
def default_cost_price_method(self):
|
||||
return 'fixed'
|
||||
|
||||
def on_change_with_default_uom_category(self, values):
|
||||
pool = Pool()
|
||||
uom_obj = pool.get('product.uom')
|
||||
if values.get('default_uom'):
|
||||
uom = uom_obj.browse(values['default_uom'])
|
||||
return uom.category.id
|
||||
|
||||
def get_default_uom_category(self, ids, name):
|
||||
categories = {}
|
||||
for template in self.browse(ids):
|
||||
categories[template.id] = template.default_uom.category.id
|
||||
return categories
|
||||
|
||||
def get_price_uom(self, ids, name):
|
||||
product_uom_obj = Pool().get('product.uom')
|
||||
res = {}
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.model.modelstorage import OPERATORS
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
STATES = {
|
||||
'readonly': ~Eval('active', True),
|
||||
@@ -94,26 +92,6 @@ class Uom(ModelSQL, ModelView):
|
||||
def default_digits(self):
|
||||
return 2
|
||||
|
||||
def default_category(self):
|
||||
product_obj = Pool().get('product.product')
|
||||
context = Transaction().context
|
||||
if 'category' in context:
|
||||
if isinstance(context['category'], (tuple, list)) \
|
||||
and len(context['category']) > 1 \
|
||||
and context['category'][1] in ('uom.category',
|
||||
'product.default_uom.category'):
|
||||
if context['category'][1] == 'uom.category':
|
||||
if not context['category'][0]:
|
||||
return False
|
||||
uom = self.browse(context['category'][0])
|
||||
return uom.category.id
|
||||
else:
|
||||
if not context['category'][0]:
|
||||
return False
|
||||
product = product_obj.browse(context['category'][0])
|
||||
return product.default_uom.category.id
|
||||
return False
|
||||
|
||||
def on_change_factor(self, value):
|
||||
if value.get('factor', 0.0) == 0.0:
|
||||
return {'rate': 0.0}
|
||||
@@ -248,38 +226,4 @@ class Uom(ModelSQL, ModelView):
|
||||
|
||||
return new_price
|
||||
|
||||
def search(self, args, offset=0, limit=None, order=None,
|
||||
count=False, query_string=False):
|
||||
product_obj = Pool().get('product.product')
|
||||
args = args[:]
|
||||
def process_args(args):
|
||||
i = 0
|
||||
while i < len(args):
|
||||
#add test for xmlrpc that doesn't handle tuple
|
||||
if (isinstance(args[i], tuple) \
|
||||
or (isinstance(args[i], list) and len(args[i]) > 2 \
|
||||
and args[i][1] in OPERATORS)) \
|
||||
and args[i][0] == 'category' \
|
||||
and isinstance(args[i][2], (list, tuple)) \
|
||||
and len(args[i][2]) == 2 \
|
||||
and args[i][2][1] in ('product.default_uom.category',
|
||||
'uom.category'):
|
||||
if not args[i][2][0]:
|
||||
args[i] = ('id', '!=', '0')
|
||||
else:
|
||||
if args[i][2][1] == 'product.default_uom.category':
|
||||
product = product_obj.browse(args[i][2][0])
|
||||
category_id = product.default_uom.category.id
|
||||
else:
|
||||
uom = self.browse(args[i][2][0])
|
||||
category_id = uom.category.id
|
||||
args[i] = (args[i][0], args[i][1], category_id)
|
||||
elif isinstance(args[i], list):
|
||||
process_args(args[i])
|
||||
i += 1
|
||||
process_args(args)
|
||||
return super(Uom, self).search(args, offset=offset, limit=limit,
|
||||
order=order, count=count,
|
||||
query_string=query_string)
|
||||
|
||||
Uom()
|
||||
Reference in new issue
Block a user