139 lines
4.8 KiB
Python
139 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, api
|
|
from lxml import etree
|
|
|
|
class ProductSupplierinfo(models.Model):
|
|
_inherit = 'product.supplierinfo'
|
|
|
|
@api.model
|
|
def get_views(self, views, options=None):
|
|
res = super().get_views(views, options)
|
|
if not self.env.user.hide_purchase_prices:
|
|
return res
|
|
|
|
for view_type, view_data in res.get('views', {}).items():
|
|
arch_str = view_data.get('arch')
|
|
if not arch_str:
|
|
continue
|
|
|
|
try:
|
|
doc = etree.fromstring(arch_str.encode('utf-8'))
|
|
except Exception:
|
|
continue
|
|
|
|
modified = False
|
|
price_fields = {
|
|
'price', 'discount', 'currency_id', 'variation_percent',
|
|
'previous_price', 'price_discounted'
|
|
}
|
|
for field in doc.xpath("//field"):
|
|
if field.get('name') in price_fields:
|
|
is_column = False
|
|
p = field.getparent()
|
|
while p is not None:
|
|
if p.tag in ('tree', 'list'):
|
|
is_column = True
|
|
break
|
|
p = p.getparent()
|
|
|
|
if is_column:
|
|
field.set('column_invisible', 'True')
|
|
else:
|
|
field.set('invisible', '1')
|
|
modified = True
|
|
|
|
if modified:
|
|
view_data['arch'] = etree.tostring(doc, encoding='utf-8').decode('utf-8')
|
|
|
|
return res
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = 'product.template'
|
|
|
|
@api.model
|
|
def get_views(self, views, options=None):
|
|
res = super().get_views(views, options)
|
|
if not self.env.user.hide_purchase_prices:
|
|
return res
|
|
|
|
for view_type, view_data in res.get('views', {}).items():
|
|
arch_str = view_data.get('arch')
|
|
if not arch_str:
|
|
continue
|
|
|
|
try:
|
|
doc = etree.fromstring(arch_str.encode('utf-8'))
|
|
except Exception:
|
|
continue
|
|
|
|
modified = False
|
|
price_fields = {
|
|
'standard_price', 'price', 'discount', 'currency_id',
|
|
'variation_percent', 'previous_price', 'price_discounted'
|
|
}
|
|
for field in doc.xpath("//field"):
|
|
if field.get('name') in price_fields:
|
|
is_column = False
|
|
p = field.getparent()
|
|
while p is not None:
|
|
if p.tag in ('tree', 'list'):
|
|
is_column = True
|
|
break
|
|
p = p.getparent()
|
|
|
|
if is_column:
|
|
field.set('column_invisible', 'True')
|
|
else:
|
|
field.set('invisible', '1')
|
|
modified = True
|
|
|
|
if modified:
|
|
view_data['arch'] = etree.tostring(doc, encoding='utf-8').decode('utf-8')
|
|
|
|
return res
|
|
|
|
class ProductProduct(models.Model):
|
|
_inherit = 'product.product'
|
|
|
|
@api.model
|
|
def get_views(self, views, options=None):
|
|
res = super().get_views(views, options)
|
|
if not self.env.user.hide_purchase_prices:
|
|
return res
|
|
|
|
for view_type, view_data in res.get('views', {}).items():
|
|
arch_str = view_data.get('arch')
|
|
if not arch_str:
|
|
continue
|
|
|
|
try:
|
|
doc = etree.fromstring(arch_str.encode('utf-8'))
|
|
except Exception:
|
|
continue
|
|
|
|
modified = False
|
|
price_fields = {
|
|
'standard_price', 'price', 'discount', 'currency_id',
|
|
'variation_percent', 'previous_price', 'price_discounted'
|
|
}
|
|
for field in doc.xpath("//field"):
|
|
if field.get('name') in price_fields:
|
|
is_column = False
|
|
p = field.getparent()
|
|
while p is not None:
|
|
if p.tag in ('tree', 'list'):
|
|
is_column = True
|
|
break
|
|
p = p.getparent()
|
|
|
|
if is_column:
|
|
field.set('column_invisible', 'True')
|
|
else:
|
|
field.set('invisible', '1')
|
|
modified = True
|
|
|
|
if modified:
|
|
view_data['arch'] = etree.tostring(doc, encoding='utf-8').decode('utf-8')
|
|
|
|
return res
|