bzr revid: fp@tinyerp.com-20081224155006-uefgofghmofr1r5g
This commit is contained in:
Fabien Pinckaers 2008-12-24 16:50:06 +01:00
commit c245b59174
11 changed files with 124 additions and 94 deletions

View File

@ -34,7 +34,7 @@ This module's aim is to check the quality of other modules.
""",
"init_xml" : [],
"update_xml" : ["base_module_quality_wizard.xml"],
"update_xml" : ["base_module_quality_wizard.xml", "security/ir.model.access.csv",],
"category" : "Tiny Specific Modules/Base module quality",
"active": False,
"installable": True

View File

@ -19,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import pooler
class abstract_quality_check(object):
'''
@ -41,11 +41,11 @@ class abstract_quality_check(object):
#This bool defines if the test can be run only if the module is installed.
#True => the module have to be installed.
#False => the module can be uninstalled.
bool_installed_only = True
bool_installed_only = True
def __init__(self):
'''
this method should initialize the var
this method should initialize the var
'''
raise 'Not Implemented'
@ -55,7 +55,27 @@ class abstract_quality_check(object):
'''
raise 'Not Implemented'
def get_objects(self, cr, uid, module):
# This function returns all object of the given module..
pool = pooler.get_pool(cr.dbname)
ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
model_list = []
model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
for model in model_data:
model_list.append(model.res_id)
obj_list = []
for mod in pool.get('ir.model').browse(cr, uid, model_list):
obj_list.append(str(mod.model))
return obj_list
def get_ids(self, cr, uid, object_list):
#This method return dictionary with ids of records of object for module
pool = pooler.get_pool(cr.dbname)
result_ids = {}
for obj in object_list:
ids = pool.get(obj).search(cr, uid, [])
result_ids[obj] = ids
return result_ids
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -16,7 +16,7 @@
</record>
<act_window
id="act_view_wiz_quality_check"
name="Wizard Quality Check"
name="Quality Check"
res_model="wizard.quality.check"
src_model="ir.module.module"
target="new"

View File

@ -42,15 +42,8 @@ This test checks if the module classes are raising exception when calling basic
def run_test(self, cr, uid, module_path):
pool = pooler.get_pool(cr.dbname)
module_name = module_path.split('/')[-1]
ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module_name), ('model','=','ir.model')])
model_list = []
model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
for model in model_data:
model_list.append(model.res_id)
obj_list = []
for mod in pool.get('ir.model').browse(cr, uid, model_list):
obj_list.append(str(mod.model))
result={}
obj_list = self.get_objects(cr, uid, module_name)
result = {}
ok_count = 0
ex_count = 0

View File

@ -0,0 +1,2 @@
"id","name","model_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_wizard_quality_check","wizard.quality.check","model_wizard_quality_check",1,1,1,1
1 id name model_id:id perm_read perm_write perm_create perm_unlink
2 access_wizard_quality_check wizard.quality.check model_wizard_quality_check 1 1 1 1

View File

@ -47,20 +47,13 @@ This test checks the speed of the module.
pool = pooler.get_pool(cr.dbname)
module_name = module_path.split('/')[-1]
self.result+=('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % ('Object Name'.ljust(40), 'Size (S)'.ljust(10), '1'.ljust(10), 'S/2'.ljust(10), 'S'.ljust(10), 'Complexity'.ljust(20))
ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module_name), ('model','=','ir.model')])
model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
model_list = []
for model in model_data:
model_list.append(model.res_id)
obj_list = []
for mod in pool.get('ir.model').browse(cr, uid, model_list):
obj_list.append(str(mod.model))
obj_list = self.get_objects(cr, uid, module_name)
obj_counter = 0
score = 0
for obj in obj_list:
obj_ids = self.get_ids(cr, uid, obj_list)
for obj in obj_ids:
obj_counter += 1
ids = pool.get(obj).search(cr, uid, [])
ids = obj_ids[obj]
ids = ids[:100]
size = len(ids)
if size:
@ -68,12 +61,10 @@ This test checks the speed of the module.
pool.get(obj).read(cr, uid, ids[0])
c2 = time.time()
base_time = c2 - c1
c1 = time.time()
pool.get(obj).read(cr, uid, ids[:size/2])
c2 = time.time()
halfsize_time = c2 - c1
c1 = time.time()
pool.get(obj).read(cr, uid, ids)
c2 = time.time()

View File

@ -31,13 +31,18 @@ import tools
class report_xml(osv.osv):
_inherit = 'ir.actions.report.xml'
def sxwtorml(self,cr, uid, file_sxw):
def sxwtorml(self,cr, uid, file_sxw,file_type):
'''
The use of this function is to get rml file from sxw file.
'''
sxwval = StringIO(base64.decodestring(file_sxw))
fp = tools.file_open('normalized_odt2rml.xsl',
subdir='/home/dsh/my-work/bazaar/odt-sxw2ml')
if file_type=='sxw':
fp = tools.file_open('normalized_oo2rml.xsl',
subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
if file_type=='odt':
fp = tools.file_open('normalized_odt2rml.xsl',
subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
def upload_report(self, cr, uid, report_id, file_sxw,file_type, context):
@ -46,11 +51,12 @@ class report_xml(osv.osv):
'''
pool = pooler.get_pool(cr.dbname)
sxwval = StringIO(base64.decodestring(file_sxw))
fp = tools.file_open('normalized_oo2rml.xsl',
subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
if file_type=='sxw':
fp = tools.file_open('normalized_oo2rml.xsl',
subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
if file_type=='odt':
fp = tools.file_open('normalized_odt2rml.xsl',
subdir='/home/dsh/my-work/bazaar/odt-sxw2ml')
subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
'report_sxw_content': base64.decodestring(file_sxw),
'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())),

View File

@ -50,6 +50,7 @@ class process_process(osv.osv):
_columns = {
'name': fields.char('Name', size=30,required=True, translate=True),
'active': fields.boolean('Active'),
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
'note': fields.text('Notes', translate=True),
'node_ids': fields.one2many('process.node', 'process_id', 'Nodes')
}
@ -59,24 +60,27 @@ class process_process(osv.osv):
def search_by_model(self, cr, uid, res_model, context):
pool = pooler.get_pool(cr.dbname)
model_ids = (res_model or None) and pool.get('ir.model').search(cr, uid, [('model', '=', res_model)])
model_ids = pool.get('ir.model').search(cr, uid, [('model', '=', res_model)])
if not model_ids:
return []
nodes = pool.get('process.node').search(cr, uid, [('model_id', 'in', model_ids)])
if not nodes:
return []
nodes = pool.get('process.node').browse(cr, uid, nodes, context)
unique = []
domain = (model_ids or []) and [('model_id', 'in', model_ids)]
result = []
for node in nodes:
if node.process_id.id not in unique:
result.append((node.process_id.id, node.process_id.name))
unique.append(node.process_id.id)
# search all processes
res = pool.get('process.process').search(cr, uid, domain)
if res:
res = pool.get('process.process').browse(cr, uid, res, context)
for process in res:
result.append((process.id, process.name))
return result
# else search process nodes
res = pool.get('process.node').search(cr, uid, domain)
if res:
res = pool.get('process.node').browse(cr, uid, res, context)
for node in res:
if (node.process_id.id, node.process_id.name) not in result:
result.append((node.process_id.id, node.process_id.name))
return result
@ -85,21 +89,27 @@ class process_process(osv.osv):
pool = pooler.get_pool(cr.dbname)
process = pool.get('process.process').browse(cr, uid, [id])[0]
current_object = pool.get(res_model).browse(cr, uid, [res_id], context)[0]
current_user = pool.get('res.users').browse(cr, uid, [uid], context)[0]
expr_context = Env(current_object, current_user)
notes = process.note
title = process.name
expr_context = {}
states = {}
perm = None
if res_model:
states = dict(pool.get(res_model).fields_get(cr, uid, context=context).get('state', {}).get('selection', {}))
if res_id:
current_object = pool.get(res_model).browse(cr, uid, [res_id], context)[0]
current_user = pool.get('res.users').browse(cr, uid, [uid], context)[0]
expr_context = Env(current_object, current_user)
title = _("%s - Resource: %s, State: %s") % (process.name, current_object.name, states.get(getattr(current_object, 'state'), 'N/A'))
perm = pool.get(res_model).perm_read(cr, uid, [res_id], context)[0]
notes = process.note or "N/A"
nodes = {}
start = []
transitions = {}
states = dict(pool.get(res_model).fields_get(cr, uid, context=context).get('state', {}).get('selection', {}))
title = "%s - Resource: %s, State: %s" % (process.name, current_object.name, states.get(getattr(current_object, 'state'), 'N/A'))
perm = pool.get(res_model).perm_read(cr, uid, [res_id], context)[0]
for node in process.node_ids:
data = {}
data['name'] = node.name
@ -126,7 +136,6 @@ class process_process(osv.osv):
try:
data['active'] = eval(node.model_states, expr_context)
except Exception, e:
# waring: invalid state expression
pass
if not data['active']:
@ -212,10 +221,11 @@ class process_process(osv.osv):
except:
pass
for nid, node in nodes.items():
if not node['gray'] and (node['active'] or node['model'] == res_model):
update_relatives(nid, res_id, res_model)
break
if res_id:
for nid, node in nodes.items():
if not node['gray'] and (node['active'] or node['model'] == res_model):
update_relatives(nid, res_id, res_model)
break
# calculate graph layout
g = tools.graph(nodes.keys(), map(lambda x: (x['source'], x['target']), transitions.values()))

View File

@ -17,6 +17,7 @@
<group colspan="4" string="Details">
<field name="name" select="1"/>
<field name="active" select="2"/>
<field name="model_id" select="1"/>
</group>
<notebook colspan="4">
<page string="Nodes">
@ -120,6 +121,7 @@
<field name="arch" type="xml">
<tree string="Process">
<field name="name"/>
<field name="model_id" select="1"/>
<field name="active"/>
</tree>
</field>

View File

@ -91,6 +91,12 @@ class product_pricelist(osv.osv):
'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'),
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
}
def name_get(self, cr, uid, ids, context={}):
result= {}
for pl in self.browse(cr, uid, ids, context):
result[pl.id] = pl.name + ' ('+ pl.currency_id.name + ')'
return result
def _get_currency(self, cr, uid, ctx):
comp = self.pool.get('res.users').browse(cr,uid,uid).company_id
if not comp:

View File

@ -43,39 +43,24 @@ class purchase_order(osv.osv):
res[order.id] += oline.price_unit * oline.product_qty
return res
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
res = {}
cur_obj=self.pool.get('res.currency')
for purchase in self.browse(cr, uid, ids):
res[purchase.id] = 0.0
for line in purchase.order_line:
res[purchase.id] += line.price_subtotal
cur = purchase.pricelist_id.currency_id
res[purchase.id] = cur_obj.round(cr, uid, cur, res[purchase.id])
return res
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
def _amount_all(self, cr, uid, ids, field_name, arg, context):
res = {}
cur_obj=self.pool.get('res.currency')
for order in self.browse(cr, uid, ids):
val = 0.0
res[order.id] = {
'amount_untaxed': 0.0,
'amount_tax': 0.0,
'amount_total': 0.0,
}
val = val1 = 0.0
cur=order.pricelist_id.currency_id
for line in order.order_line:
for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id, order.partner_id):
val+= c['amount']
res[order.id]=cur_obj.round(cr, uid, cur, val)
return res
def _amount_total(self, cr, uid, ids, field_name, arg, context):
res = {}
untax = self._amount_untaxed(cr, uid, ids, field_name, arg, context)
tax = self._amount_tax(cr, uid, ids, field_name, arg, context)
cur_obj=self.pool.get('res.currency')
for id in ids:
order=self.browse(cr, uid, [id])[0]
cur=order.pricelist_id.currency_id
res[id] = cur_obj.round(cr, uid, cur, untax.get(id, 0.0) + tax.get(id, 0.0))
val1 += line.price_subtotal
res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
return res
def _set_minimum_planned_date(self, cr, uid, ids, name, value, arg, context):
@ -144,6 +129,12 @@ class purchase_order(osv.osv):
res[r] = 100.0 * res[r][0] / res[r][1]
return res
def _get_order(self, cr, uid, ids, context={}):
result = {}
for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
result[line.order_id.id] = True
return result.keys()
_columns = {
'name': fields.char('Order Reference', size=64, required=True, select=True),
'origin': fields.char('Origin', size=64,
@ -181,9 +172,18 @@ class purchase_order(osv.osv):
"Manual: no invoice will be pre-generated. The accountant will have to encode manually."
),
'minimum_planned_date':fields.function(_minimum_planned_date, fnct_inv=_set_minimum_planned_date, method=True,store=True, string='Planned Date', type='datetime', help="This is computed as the minimum scheduled date of all purchase order lines' products."),
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
'amount_total': fields.function(_amount_total, method=True, string='Total'),
'amount_untaxed': fields.function(_amount_all, method=True, string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums"),
'amount_tax': fields.function(_amount_all, method=True, string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums"),
'amount_total': fields.function(_amount_all, method=True, string='Total',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums"),
}
_defaults = {
'date_order': lambda *a: time.strftime('%Y-%m-%d'),