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" : [], "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", "category" : "Tiny Specific Modules/Base module quality",
"active": False, "active": False,
"installable": True "installable": True

View File

@ -19,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import pooler
class abstract_quality_check(object): 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. #This bool defines if the test can be run only if the module is installed.
#True => the module have to be installed. #True => the module have to be installed.
#False => the module can be uninstalled. #False => the module can be uninstalled.
bool_installed_only = True bool_installed_only = True
def __init__(self): def __init__(self):
''' '''
this method should initialize the var this method should initialize the var
''' '''
raise 'Not Implemented' raise 'Not Implemented'
@ -55,7 +55,27 @@ class abstract_quality_check(object):
''' '''
raise 'Not Implemented' 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: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -16,7 +16,7 @@
</record> </record>
<act_window <act_window
id="act_view_wiz_quality_check" id="act_view_wiz_quality_check"
name="Wizard Quality Check" name="Quality Check"
res_model="wizard.quality.check" res_model="wizard.quality.check"
src_model="ir.module.module" src_model="ir.module.module"
target="new" 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): def run_test(self, cr, uid, module_path):
pool = pooler.get_pool(cr.dbname) pool = pooler.get_pool(cr.dbname)
module_name = module_path.split('/')[-1] module_name = module_path.split('/')[-1]
ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module_name), ('model','=','ir.model')]) obj_list = self.get_objects(cr, uid, module_name)
model_list = [] result = {}
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={}
ok_count = 0 ok_count = 0
ex_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) pool = pooler.get_pool(cr.dbname)
module_name = module_path.split('/')[-1] 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)) 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')]) obj_list = self.get_objects(cr, uid, module_name)
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_counter = 0 obj_counter = 0
score = 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 obj_counter += 1
ids = pool.get(obj).search(cr, uid, []) ids = obj_ids[obj]
ids = ids[:100] ids = ids[:100]
size = len(ids) size = len(ids)
if size: if size:
@ -68,12 +61,10 @@ This test checks the speed of the module.
pool.get(obj).read(cr, uid, ids[0]) pool.get(obj).read(cr, uid, ids[0])
c2 = time.time() c2 = time.time()
base_time = c2 - c1 base_time = c2 - c1
c1 = time.time() c1 = time.time()
pool.get(obj).read(cr, uid, ids[:size/2]) pool.get(obj).read(cr, uid, ids[:size/2])
c2 = time.time() c2 = time.time()
halfsize_time = c2 - c1 halfsize_time = c2 - c1
c1 = time.time() c1 = time.time()
pool.get(obj).read(cr, uid, ids) pool.get(obj).read(cr, uid, ids)
c2 = time.time() c2 = time.time()

View File

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

View File

@ -50,6 +50,7 @@ class process_process(osv.osv):
_columns = { _columns = {
'name': fields.char('Name', size=30,required=True, translate=True), 'name': fields.char('Name', size=30,required=True, translate=True),
'active': fields.boolean('Active'), 'active': fields.boolean('Active'),
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
'note': fields.text('Notes', translate=True), 'note': fields.text('Notes', translate=True),
'node_ids': fields.one2many('process.node', 'process_id', 'Nodes') '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): def search_by_model(self, cr, uid, res_model, context):
pool = pooler.get_pool(cr.dbname) 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)]) domain = (model_ids or []) and [('model_id', 'in', model_ids)]
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 = []
result = [] result = []
for node in nodes: # search all processes
if node.process_id.id not in unique: res = pool.get('process.process').search(cr, uid, domain)
result.append((node.process_id.id, node.process_id.name)) if res:
unique.append(node.process_id.id) 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 return result
@ -85,21 +89,27 @@ class process_process(osv.osv):
pool = pooler.get_pool(cr.dbname) pool = pooler.get_pool(cr.dbname)
process = pool.get('process.process').browse(cr, uid, [id])[0] process = pool.get('process.process').browse(cr, uid, [id])[0]
current_object = pool.get(res_model).browse(cr, uid, [res_id], context)[0] title = process.name
current_user = pool.get('res.users').browse(cr, uid, [uid], context)[0]
expr_context = {}
expr_context = Env(current_object, current_user) states = {}
perm = None
notes = process.note
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 = {} nodes = {}
start = [] start = []
transitions = {} 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: for node in process.node_ids:
data = {} data = {}
data['name'] = node.name data['name'] = node.name
@ -126,7 +136,6 @@ class process_process(osv.osv):
try: try:
data['active'] = eval(node.model_states, expr_context) data['active'] = eval(node.model_states, expr_context)
except Exception, e: except Exception, e:
# waring: invalid state expression
pass pass
if not data['active']: if not data['active']:
@ -212,10 +221,11 @@ class process_process(osv.osv):
except: except:
pass pass
for nid, node in nodes.items(): if res_id:
if not node['gray'] and (node['active'] or node['model'] == res_model): for nid, node in nodes.items():
update_relatives(nid, res_id, res_model) if not node['gray'] and (node['active'] or node['model'] == res_model):
break update_relatives(nid, res_id, res_model)
break
# calculate graph layout # calculate graph layout
g = tools.graph(nodes.keys(), map(lambda x: (x['source'], x['target']), transitions.values())) 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"> <group colspan="4" string="Details">
<field name="name" select="1"/> <field name="name" select="1"/>
<field name="active" select="2"/> <field name="active" select="2"/>
<field name="model_id" select="1"/>
</group> </group>
<notebook colspan="4"> <notebook colspan="4">
<page string="Nodes"> <page string="Nodes">
@ -120,6 +121,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Process"> <tree string="Process">
<field name="name"/> <field name="name"/>
<field name="model_id" select="1"/>
<field name="active"/> <field name="active"/>
</tree> </tree>
</field> </field>

View File

@ -91,6 +91,12 @@ class product_pricelist(osv.osv):
'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'), 'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'),
'currency_id': fields.many2one('res.currency', 'Currency', required=True), '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): def _get_currency(self, cr, uid, ctx):
comp = self.pool.get('res.users').browse(cr,uid,uid).company_id comp = self.pool.get('res.users').browse(cr,uid,uid).company_id
if not comp: if not comp:

View File

@ -43,39 +43,24 @@ class purchase_order(osv.osv):
res[order.id] += oline.price_unit * oline.product_qty res[order.id] += oline.price_unit * oline.product_qty
return res return res
def _amount_untaxed(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 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):
res = {} res = {}
cur_obj=self.pool.get('res.currency') cur_obj=self.pool.get('res.currency')
for order in self.browse(cr, uid, ids): 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 cur=order.pricelist_id.currency_id
for line in order.order_line: 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): 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'] val+= c['amount']
res[order.id]=cur_obj.round(cr, uid, cur, val) val1 += line.price_subtotal
return res res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
def _amount_total(self, cr, uid, ids, field_name, arg, context): res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
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))
return res return res
def _set_minimum_planned_date(self, cr, uid, ids, name, value, arg, context): 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] res[r] = 100.0 * res[r][0] / res[r][1]
return res 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 = { _columns = {
'name': fields.char('Order Reference', size=64, required=True, select=True), 'name': fields.char('Order Reference', size=64, required=True, select=True),
'origin': fields.char('Origin', size=64, '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." "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."), '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_untaxed': fields.function(_amount_all, method=True, string='Untaxed Amount',
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'), store={
'amount_total': fields.function(_amount_total, method=True, string='Total'), '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 = { _defaults = {
'date_order': lambda *a: time.strftime('%Y-%m-%d'), 'date_order': lambda *a: time.strftime('%Y-%m-%d'),