rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
"AND (s.shop_id IN %s)" %(tuple(so_line), tuple(so), company, tuple(shops)))
"AND (s.shop_id IN %s)" ,(tuple(so_line), tuple(so), company, tuple(shops)))
def _sales_per_warehouse(self, cr, uid, so, so_line, company, shops): cr.execute("SELECT sum(sol.product_uom_qty) FROM sale_order_line AS sol LEFT JOIN sale_order AS s ON (s.id = sol.order_id) " \ "WHERE (sol.id IN %s) AND (s.state NOT IN (\'draft\',\'cancel\')) AND (s.id IN %s)AND (s.company_id=%s) " \ "AND (s.shop_id IN %s)" %(tuple(so_line), tuple(so), company, tuple(shops))) ret = cr.fetchone()[0] or 0.0 return ret
dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),))
cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" ,(tuple(dept_ids),))
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context)
so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ], context = context)
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
so_period_set = ','.join(map(str,so_period_ids))
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set)
sales[i][0] =self._sales_per_users(cr, uid, so_period_ids, so_line_product_ids, obj.company_id.id, user_set)
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set)
sales[i][1]= self._sales_per_users(cr, uid, so_period_ids, so_line_product_ids, obj.company_id.id, dept_users_set)
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set)
sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_ids, so_line_product_ids, obj.company_id.id, shops_set)
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, )
sales[i][3]= self._sales_per_company(cr, uid, so_period_ids, so_line_product_ids, obj.company_id.id, )
def calculate_sales_history(self, cr, uid, ids, context, *args): sales=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],] for obj in self.browse(cr, uid, ids): periods =obj.analyzed_period1_id, obj.analyzed_period2_id, obj.analyzed_period3_id, obj.analyzed_period4_id, obj.analyzed_period5_id so_obj = self.pool.get('sale.order') so_line_obj= self.pool.get('sale.order.line') so_line_product_ids = so_line_obj.search(cr, uid, [('product_id','=', obj.product_id.id)], context = context) if so_line_product_ids: so_line_product_set = ','.join(map(str,so_line_product_ids)) if obj.analyzed_warehouse_id: shops = self.pool.get('sale.shop').search(cr, uid,[('warehouse_id','=', obj.analyzed_warehouse_id.id)], context = context) shops_set = ','.join(map(str,shops)) else: shops = False if obj.analyzed_dept_id: dept_obj = self.pool.get('hr.department') dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or [] dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)]) dept_ids_set = ','.join(map(str,dept_ids)) cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" %(tuple(dept_ids_set),)) dept_users = [x for x, in cr.fetchall()] dept_users_set = ','.join(map(str,dept_users)) else: dept_users = False factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context) for i, period in enumerate(periods): if period: so_period_ids = so_obj.search(cr, uid, [('date_order','>=',period.date_start), ('date_order','<=',period.date_stop)], context = context) if so_period_ids: so_period_set = ','.join(map(str,so_period_ids)) if obj.analyzed_user_id: user_set = str(obj.analyzed_user_id.id) sales[i][0] =self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, user_set) sales[i][0] *=factor if dept_users: sales[i][1]= self._sales_per_users(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, dept_users_set) sales[i][1]*=factor if shops: sales[i][2]= self._sales_per_warehouse(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, shops_set) sales[i][2]*=factor if obj.analyze_company: sales[i][3]= self._sales_per_company(cr, uid, so_period_set, so_line_product_set, obj.company_id.id, ) sales[i][3]*=factor self.write(cr, uid, ids, { 'analyzed_period1_per_user':sales[0][0], 'analyzed_period2_per_user':sales[1][0], 'analyzed_period3_per_user':sales[2][0], 'analyzed_period4_per_user':sales[3][0], 'analyzed_period5_per_user':sales[4][0], 'analyzed_period1_per_dept':sales[0][1], 'analyzed_period2_per_dept':sales[1][1], 'analyzed_period3_per_dept':sales[2][1], 'analyzed_period4_per_dept':sales[3][1], 'analyzed_period5_per_dept':sales[4][1], 'analyzed_period1_per_warehouse':sales[0][2], 'analyzed_period2_per_warehouse':sales[1][2], 'analyzed_period3_per_warehouse':sales[2][2], 'analyzed_period4_per_warehouse':sales[3][2], 'analyzed_period5_per_warehouse':sales[4][2], 'analyzed_period1_per_company':sales[0][3], 'analyzed_period2_per_company':sales[1][3], 'analyzed_period3_per_company':sales[2][3], 'analyzed_period4_per_company':sales[3][3], 'analyzed_period5_per_company':sales[4][3], }) return True
'get_start_date': self.get_start_date, 'get_end_date': self.get_end_date
def __init__(self, cr, uid, name, context=None): if context is None: context = {} super(journal_print, self).__init__(cr, uid, name, context=context) self.period_ids = [] self.journal_ids = [] self.localcontext.update({ 'time': time, 'lines': self.lines, 'sum_debit': self._sum_debit, 'sum_credit': self._sum_credit, 'get_start_date': self.get_start_date, 'get_end_date': self.get_end_date })
if isinstance(ids, (str, int, long)): ids = [ids] data = super(ir_model, self).read(cr, uid, ids, fields=fields, \
new_ids = isinstance(ids, (str, int, long)) and [ids] or ids data = super(ir_model, self).read(cr, uid, new_ids, fields=fields, \
def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'): """ Read IR Model @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of IR Model’s IDs. @param context: A standard dictionary for contextual values """
return data
return new_ids = isinstance(ids, (str, int, long)) and data[0] or data
def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'): """ Read IR Model @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of IR Model’s IDs. @param context: A standard dictionary for contextual values """
def desperate_fixer(g): return ' ' html = re.sub('<.*?>', desperate_fixer, html)
html = re.sub('<.*?>', ' ', html)
def html2plaintext(html, body_id=None, encoding='utf-8'): ## (c) Fry-IT, www.fry-it.com, 2007 ## <peter@fry-it.com> ## download here: http://www.peterbe.com/plog/html2plaintext """ from an HTML text, convert the HTML to plain text. If @body_id is provided then this is the tag where the body (not necessarily <body>) starts. """ try: from BeautifulSoup import BeautifulSoup, SoupStrainer, Comment except: return html urls = [] if body_id is not None: strainer = SoupStrainer(id=body_id) else: strainer = SoupStrainer('body') soup = BeautifulSoup(html, parseOnlyThese=strainer, fromEncoding=encoding) for link in soup.findAll('a'): title = unicode(link) for url in [x[1] for x in link.attrs if x[0]=='href']: urls.append(dict(url=url, tag=unicode(link), title=title)) html = unicode(soup) url_index = [] i = 0 for d in urls: if d['title'] == d['url'] or 'http://'+d['title'] == d['url']: html = html.replace(d['tag'], d['url']) else: i += 1 html = html.replace(d['tag'], '%s [%s]' % (d['title'], i)) url_index.append(d['url']) html = html.replace('<strong>', '*').replace('</strong>', '*') html = html.replace('<b>', '*').replace('</b>', '*') html = html.replace('<h3>', '*').replace('</h3>', '*') html = html.replace('<h2>', '**').replace('</h2>', '**') html = html.replace('<h1>', '**').replace('</h1>', '**') html = html.replace('<em>', '/').replace('</em>', '/') # the only line breaks we respect is those of ending tags and # breaks html = html.replace('\n', ' ') html = html.replace('<br>', '\n') html = html.replace('<tr>', '\n') html = html.replace('</p>', '\n\n') html = re.sub('<br\s*/>', '\n', html) html = html.replace(' ' * 2, ' ') # for all other tags we failed to clean up, just remove then and # complain about them on the stderr def desperate_fixer(g): #print >>sys.stderr, "failed to clean up %s" % str(g.group()) return ' ' html = re.sub('<.*?>', desperate_fixer, html) # lstrip all lines html = '\n'.join([x.lstrip() for x in html.splitlines()]) for i, url in enumerate(url_index): if i == 0: html += '\n\n' html += '[%s] %s\n' % (i+1, url) return html
def _decode_header(self, s):
def _decode_header(self, text):
def _decode_header(self, s): from email.Header import decode_header s = decode_header(s.replace('\r', '')) return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or []))
s = decode_header(s.replace('\r', '')) return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or []))
if text: text = decode_header(text.replace('\r', '')) return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), text or []))
def _decode_header(self, s): from email.Header import decode_header s = decode_header(s.replace('\r', '')) return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or []))
try: id = self.rpc(self.model, 'create', data) self.rpc(self.model, 'history', [id], 'Receive', True, msg_to, message['body'], msg_from, False, {'model' : self.model}) except Exception, e: if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode: e = '\n\nThe Specified user does not have an access to the CRM case.' print e
values = { 'message_ids' : [ (0, 0, { 'model_id' : self.rpc('ir.model', 'search', [('name', '=', self.model)])[0], 'date' : time.strftime('%Y-%m-%d %H:%M:%S'), 'description' : message['body'], 'email_from' : msg_from, 'email_to' : msg_to, 'name' : 'Receive', 'history' : True, 'user_id' : self.rpc.user_id, } ) ] } thread_id = self.rpc('mailgate.thread', 'create', values) data['thread_id'] = thread_id oid = self.rpc(self.model, 'create', data)
def msg_new(self, msg): message = self.msg_body_get(msg) msg_subject = self._decode_header(msg['Subject']) msg_from = self._decode_header(msg['From']) msg_to = self._decode_header(msg['To']) msg_cc = self._decode_header(msg['Cc'] or '') data = { 'name': msg_subject, 'email_from': msg_from, 'email_cc': msg_cc, 'user_id': False, 'description': message['body'], 'state' : 'draft', } data.update(self.partner_get(msg_from))
'res_id': id
'res_id': oid
def msg_new(self, msg): message = self.msg_body_get(msg) msg_subject = self._decode_header(msg['Subject']) msg_from = self._decode_header(msg['From']) msg_to = self._decode_header(msg['To']) msg_cc = self._decode_header(msg['Cc'] or '') data = { 'name': msg_subject, 'email_from': msg_from, 'email_cc': msg_cc, 'user_id': False, 'description': message['body'], 'state' : 'draft', } data.update(self.partner_get(msg_from))
return id
return (oid, thread_id,)
def msg_new(self, msg): message = self.msg_body_get(msg) msg_subject = self._decode_header(msg['Subject']) msg_from = self._decode_header(msg['From']) msg_to = self._decode_header(msg['To']) msg_cc = self._decode_header(msg['Cc'] or '') data = { 'name': msg_subject, 'email_from': msg_from, 'email_cc': msg_cc, 'user_id': False, 'description': message['body'], 'state' : 'draft', } data.update(self.partner_get(msg_from))
message = {}; message['body'] = ''; message['attachment'] = {};
message = { 'body' : '', 'attachment' : {}, }
def msg_body_get(self, msg): message = {}; message['body'] = ''; message['attachment'] = {}; attachment = message['attachment']; counter = 1; def replace(match): return ''
def replace(match): return ''
def replace(match): return ''
txt = re.sub("<(\w)>", replace, txt) txt = re.sub("<\/(\w)>", replace, txt)
txt = re.sub("<\/?(\w)>", '', txt)
def replace(match): return ''
elif part.get_content_maintype()=='application' or part.get_content_maintype()=='image' or part.get_content_maintype()=='text':
elif part.get_content_maintype() in ('application', 'image', 'text'):
def replace(match): return ''
if filename : attachment[filename] = part.get_payload(decode=True); else:
if not filename :
def replace(match): return ''
self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['To']), body['body'], self._decode_header(msg['From']), False, {'model' : self.model})
self.create_message(id, msg['From'], msg['To'], 'Send', message['body'])
def msg_user(self, msg, id): body = self.msg_body_get(msg)
if not len(emails):
if not emails:
def msg_send(self, msg, emails, priority=None): if not len(emails): return False del msg['To'] msg['To'] = emails[0] if len(emails)>1: if 'Cc' in msg: del msg['Cc'] msg['Cc'] = ','.join(emails[1:]) del msg['Reply-To'] msg['Reply-To'] = self.email if priority: msg['X-Priority'] = priorities.get(priority, '3 (Normal)') s = smtplib.SMTP() s.connect() s.sendmail(self.email, emails, msg.as_string()) s.close() return True
del msg['To']
def msg_send(self, msg, emails, priority=None): if not len(emails): return False del msg['To'] msg['To'] = emails[0] if len(emails)>1: if 'Cc' in msg: del msg['Cc'] msg['Cc'] = ','.join(emails[1:]) del msg['Reply-To'] msg['Reply-To'] = self.email if priority: msg['X-Priority'] = priorities.get(priority, '3 (Normal)') s = smtplib.SMTP() s.connect() s.sendmail(self.email, emails, msg.as_string()) s.close() return True
if len(emails)>1: if 'Cc' in msg: del msg['Cc']
if len(emails) > 1:
def msg_send(self, msg, emails, priority=None): if not len(emails): return False del msg['To'] msg['To'] = emails[0] if len(emails)>1: if 'Cc' in msg: del msg['Cc'] msg['Cc'] = ','.join(emails[1:]) del msg['Reply-To'] msg['Reply-To'] = self.email if priority: msg['X-Priority'] = priorities.get(priority, '3 (Normal)') s = smtplib.SMTP() s.connect() s.sendmail(self.email, emails, msg.as_string()) s.close() return True
del msg['Reply-To']
def msg_send(self, msg, emails, priority=None): if not len(emails): return False del msg['To'] msg['To'] = emails[0] if len(emails)>1: if 'Cc' in msg: del msg['Cc'] msg['Cc'] = ','.join(emails[1:]) del msg['Reply-To'] msg['Reply-To'] = self.email if priority: msg['X-Priority'] = priorities.get(priority, '3 (Normal)') s = smtplib.SMTP() s.connect() s.sendmail(self.email, emails, msg.as_string()) s.close() return True
self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['To']), message['body'], self._decode_header(msg['From']), False, {'model' : self.model})
self.create_message(id, msg['From'], msg['To'], 'Send', message['body'])
def msg_partner(self, msg, id): message = self.msg_body_get(msg) body = message['body'] act = 'case_open' self.rpc(self.model, act, [id]) #body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n'))) #data = { # 'description':body, #} #self.rpc(self.model, 'write', [id], data) attachments = message['attachment'] for attach in attachments or []: data_attach = { 'name': str(attach), 'datas': binascii.b2a_base64(str(attachments[attach])), 'datas_fname': str(attach), 'description': 'Mail attachment', 'res_model': self.model, 'res_id': id } self.rpc('ir.attachment', 'create', data_attach)
emails = self.rpc(self.model, 'emails_get', int(case_str)) return (int(case_str), emails)
case_id = int(case_str) emails = self.rpc(self.model, 'emails_get', [case_id]) return (case_id, emails)
def msg_test(self, msg, case_str): if not case_str: return (False, False) emails = self.rpc(self.model, 'emails_get', int(case_str)) return (int(case_str), emails)
if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])):
values = self.rpc(self.model, 'read', [case_id], ['thread_id']) if values: thread_id = values[0]['thread_id'][0] emails = emails[str(thread_id)] user_email = filter(None, emails['user_email'])[0] if user_email and self.email_get(user_email) == self.email_get(self._decode_header(msg['From'])):
def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) if case_str: case_str = case_str.group(1) else: case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>' emails = self.rpc(self.model, 'emails_get', case_id) priority = emails[3] em = [emails[0], emails[1]] + (emails[2] or '').split(',')
case_id, thread_id = self.msg_new(msg) subject = self._decode_header(msg['Subject']) msg['Subject'] = "[%s] %s" % (case_id, subject,) msg['Message-Id'] = "<%s-openerpcrm-%s@%s>" % (time.time(), case_id, socket.gethostname(),) logging.info(" case: %r", case_id) logging.info(" thread: %r", thread_id) values = self.rpc(self.model, 'emails_get', [case_id]) emails = values[str(thread_id)] priority = emails.get('piority', [3])[0] em = emails['user_email'] + emails['email_from'] + emails['email_cc']
def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) if case_str: case_str = case_str.group(1) else: case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
del msg['Subject']
def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) if case_str: case_str = case_str.group(1) else: case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
return case_id, emails
return case_id, thread_id, emails
def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) if case_str: case_str = case_str.group(1) else: case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
import sys, optparse
def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) if case_str: case_str = case_str.group(1) else: case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: case_id = self.msg_new(msg) subject = self._decode_header(msg['subject']) if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
'remaining_hours' : fields.float('Remaining Hours', digits=(16,2), help="Re-estimated time that will change the remaining hours of the task"), }
'remaining_hours' : fields.float('Remaining Hours', digits=(16,2), help="Put here the remaining hours required to close the task."), }
def _get_remaining(self,cr, uid, ctx): task_obj = self.pool.get('project.task') if 'active_id' in ctx: return task_obj.browse(cr,uid,ctx['active_id'],context=ctx).remaining_hours return False
amount = 0.0
def onchange_partner_id(self, cr, uid, ids, partner_id, ttype, journal_id=False, context={}): """ Returns a dict that contains new values and context @param cr: A database cursor @param user: ID of the user currently logged in @param partner_id: latest value from user input for field partner_id @param args: other arguments @param context: context arguments, like lang, time zone @return: Returns a dict which contains new values, and context """ move_pool = self.pool.get('account.move') line_pool = self.pool.get('account.voucher.line') move_line_pool = self.pool.get('account.move.line') partner_pool = self.pool.get('res.partner') journal_pool = self.pool.get('account.journal') res = [] context.update({ 'type':ttype, 'partner_id':partner_id, 'voucher':True, }) if journal_id: context.update({ 'journal_id':journal_id, }) default = { 'value':{}, 'context':context, } if not partner_id or not ttype: if ids: line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])]) if line_ids: line_pool.unlink(cr, uid, line_ids) return default account_id = False partner = partner_pool.browse(cr, uid, partner_id) if ttype in ('sale'): account_id = partner.property_account_receivable.id elif ttype in ('purchase'): account_id = partner.property_account_payable.id elif ttype in ('payment', 'receipt'): journal = journal_pool.browse(cr, uid, journal_id) if ttype == 'payment': account_id = journal.default_credit_account_id.id elif ttype == 'receipt': account_id = journal.default_debit_account_id.id default['value'].update({ 'account_id':account_id }) if ttype not in ('payment', 'receipt'): return default voucher_id = ids and ids[0] or False search_type = 'credit' account_type = False if ttype == 'receipt': search_type = 'debit' account_type = 'receivable' elif ttype == 'payment': search_type = 'credit' account_type = 'payable'
'amount':line.credit
def onchange_partner_id(self, cr, uid, ids, partner_id, ttype, journal_id=False, context={}): """ Returns a dict that contains new values and context @param cr: A database cursor @param user: ID of the user currently logged in @param partner_id: latest value from user input for field partner_id @param args: other arguments @param context: context arguments, like lang, time zone @return: Returns a dict which contains new values, and context """ move_pool = self.pool.get('account.move') line_pool = self.pool.get('account.voucher.line') move_line_pool = self.pool.get('account.move.line') partner_pool = self.pool.get('res.partner') journal_pool = self.pool.get('account.journal') res = [] context.update({ 'type':ttype, 'partner_id':partner_id, 'voucher':True, }) if journal_id: context.update({ 'journal_id':journal_id, }) default = { 'value':{}, 'context':context, } if not partner_id or not ttype: if ids: line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])]) if line_ids: line_pool.unlink(cr, uid, line_ids) return default account_id = False partner = partner_pool.browse(cr, uid, partner_id) if ttype in ('sale'): account_id = partner.property_account_receivable.id elif ttype in ('purchase'): account_id = partner.property_account_payable.id elif ttype in ('payment', 'receipt'): journal = journal_pool.browse(cr, uid, journal_id) if ttype == 'payment': account_id = journal.default_credit_account_id.id elif ttype == 'receipt': account_id = journal.default_debit_account_id.id default['value'].update({ 'account_id':account_id }) if ttype not in ('payment', 'receipt'): return default voucher_id = ids and ids[0] or False search_type = 'credit' account_type = False if ttype == 'receipt': search_type = 'debit' account_type = 'receivable' elif ttype == 'payment': search_type = 'credit' account_type = 'payable'
'amount':line.debit
def onchange_partner_id(self, cr, uid, ids, partner_id, ttype, journal_id=False, context={}): """ Returns a dict that contains new values and context @param cr: A database cursor @param user: ID of the user currently logged in @param partner_id: latest value from user input for field partner_id @param args: other arguments @param context: context arguments, like lang, time zone @return: Returns a dict which contains new values, and context """ move_pool = self.pool.get('account.move') line_pool = self.pool.get('account.voucher.line') move_line_pool = self.pool.get('account.move.line') partner_pool = self.pool.get('res.partner') journal_pool = self.pool.get('account.journal') res = [] context.update({ 'type':ttype, 'partner_id':partner_id, 'voucher':True, }) if journal_id: context.update({ 'journal_id':journal_id, }) default = { 'value':{}, 'context':context, } if not partner_id or not ttype: if ids: line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])]) if line_ids: line_pool.unlink(cr, uid, line_ids) return default account_id = False partner = partner_pool.browse(cr, uid, partner_id) if ttype in ('sale'): account_id = partner.property_account_receivable.id elif ttype in ('purchase'): account_id = partner.property_account_payable.id elif ttype in ('payment', 'receipt'): journal = journal_pool.browse(cr, uid, journal_id) if ttype == 'payment': account_id = journal.default_credit_account_id.id elif ttype == 'receipt': account_id = journal.default_debit_account_id.id default['value'].update({ 'account_id':account_id }) if ttype not in ('payment', 'receipt'): return default voucher_id = ids and ids[0] or False search_type = 'credit' account_type = False if ttype == 'receipt': search_type = 'debit' account_type = 'receivable' elif ttype == 'payment': search_type = 'credit' account_type = 'payable'
'name':inv.name,
'name':inv.name and inv.name or '/',
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
rec_ids = []
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
rec_ids = []
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
'name':line.name,
'name':line.name and line.name or '/',
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
for move_line in line.move_id.line_id: if line.account_id.id == move_line.account_id.id: rec_ids += [move_line.id]
if line.move_line_id: rec_ids += [line.move_line_id.id] if rec_ids: cr.commit() move_line_pool.reconcile_partial(cr, uid, rec_ids)
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
'name':inv.tax_id.name,
'name':name,
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
if rec_ids: move_line_pool.reconcile_partial(cr, uid, rec_ids)
def action_move_line_create(self, cr, uid, ids, *args): journal_pool = self.pool.get('account.journal') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') move_line_pool = self.pool.get('account.move.line') analytic_pool = self.pool.get('account.analytic.line') currency_pool = self.pool.get('res.currency') invoice_pool = self.pool.get('account.invoice') for inv in self.browse(cr, uid, ids): if inv.move_id: continue
cr.execute(""" SELECT move.id FROM stock_picking pick RIGHT JOIN stock_move move ON move.picking_id = pick.id AND move.state = %s WHERE pick.id = %s""", ('done', move.picking_id.id)) res = cr.fetchall() if len(res) == len(move.picking_id.move_lines): picking_obj.action_move(cr, uid, [move.picking_id.id]) wf_service.trg_validate(uid, 'stock.picking', move.picking_id.id, 'button_done', cr)
if move.picking_id.id : cr.execute(""" SELECT move.id FROM stock_picking pick RIGHT JOIN stock_move move ON move.picking_id = pick.id AND move.state = %s WHERE pick.id = %s""", ('done', move.picking_id.id)) res = cr.fetchall() if len(res) == len(move.picking_id.move_lines): picking_obj.action_move(cr, uid, [move.picking_id.id]) wf_service.trg_validate(uid, 'stock.picking', move.picking_id.id, 'button_done', cr)
def do_partial(self, cr, uid, ids, partial_datas, context={}): """ Makes partial pickings and moves done. @param partial_datas: Dictionary containing details of partial picking like partner_id, address_id, delivery_date, delivery moves with product_id, product_qty, uom """ res = {} picking_obj = self.pool.get('stock.picking') product_obj = self.pool.get('product.product') currency_obj = self.pool.get('res.currency') users_obj = self.pool.get('res.users') uom_obj = self.pool.get('product.uom') price_type_obj = self.pool.get('product.price.type') sequence_obj = self.pool.get('ir.sequence') wf_service = netsvc.LocalService("workflow") partner_id = partial_datas.get('partner_id', False) address_id = partial_datas.get('address_id', False) delivery_date = partial_datas.get('delivery_date', False) tracking_lot = context.get('tracking_lot', False)
where id=%%d' % model_obj._table,(datas.id,))
where id=%%s' % model_obj._table,(datas.id,))
def do_alarm_unlink(self, cr, uid, ids, model, context=None): """ Delete alarm specified in ids @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of res alarm’s IDs. @param model: Model name for which alarm is to be cleared. @return: True """ if not context: context = {} alarm_obj = self.pool.get('calendar.alarm') ir_obj = self.pool.get('ir.model') model_id = ir_obj.search(cr, uid, [('model', '=', model)])[0] model_obj = self.pool.get(model) for datas in model_obj.browse(cr, uid, ids, context): alarm_ids = alarm_obj.search(cr, uid, [('model_id', '=', model_id), ('res_id', '=', datas.id)]) if alarm_ids: alarm_obj.unlink(cr, uid, alarm_ids) cr.execute('Update %s set base_calendar_alarm_id=NULL, alarm_id=NULL\ where id=%%d' % model_obj._table,(datas.id,)) return True
cr.execute('select id from %s where recurrent_uid=%s' % (self._table, event_id))
cr.execute('select id from %s where recurrent_uid=%s' , (self._table, event_id))
def unlink_events(self, cr, uid, ids, context=None): """ This function deletes event which are linked with the event with recurrent_uid (Removes the events which refers to the same UID value) """ if not context: context = {} for event_id in ids: cr.execute('select id from %s where recurrent_uid=%s' % (self._table, event_id)) r_ids = map(lambda x: x[0], cr.fetchall()) self.unlink(cr, uid, r_ids, context=context) return True
to_write.update({'email_cc' : case.email_cc or '' + ','.join(new_cc)})
to_write.update({'email_cc' : ', '.join(new_cc) })
def action_forward(self, cr, uid, ids, context=None): """ Forward the lead to a partner """ this = self.browse(cr, uid, ids[0], context=context) case_pool = self.pool.get(context.get('active_model')) res_id = context and context.get('active_id', False) or False case = case_pool.browse(cr, uid, res_id, context=context)
self.log(cr, user, id, message) return super(stock_picking, self).create(cr, user, vals, context)
self.log(cr, user, new_id, message) return new_id
def create(self, cr, user, vals, context=None): if ('name' not in vals) or (vals.get('name')=='/'): vals['name'] = self.pool.get('ir.sequence').get(cr, user, 'stock.picking') type_list = { 'out':_('Packing List'), 'in':_('Reception'), 'internal': _('Internal picking'), 'delivery': _('Delivery order') } if not vals.get('auto_picking', False): message = type_list.get(vals.get('type', False), _('Picking')) + " '" + (vals['name'] or "n/a") + "' "+ _("created.") self.log(cr, user, id, message) return super(stock_picking, self).create(cr, user, vals, context)
res_user=self.pool.get('res.users').browse(cr,uid,uid)
def action_move_create(self, cr, uid, ids,context=None): proc_obj = self.pool.get('procurement.order') move_obj = self.pool.get('stock.move') location_obj = self.pool.get('stock.location') wf_service = netsvc.LocalService("workflow")
'company_id': line.company_id and line.company_id.id or False,
'company_id': res_user.company_id and res_user.company_id.id or False,
def action_move_create(self, cr, uid, ids,context=None): proc_obj = self.pool.get('procurement.order') move_obj = self.pool.get('stock.move') location_obj = self.pool.get('stock.location') wf_service = netsvc.LocalService("workflow")
message = _('Invoice ') + " '" + inv.name + "' "+ _("is confirm") self.log(cr, uid, inv.id, message)
def action_move_create(self, cr, uid, ids, *args): """Creates invoice related analytics and financial move lines""" ait_obj = self.pool.get('account.invoice.tax') cur_obj = self.pool.get('res.currency') context = {} for inv in self.browse(cr, uid, ids): if not inv.journal_id.invoice_sequence_id: raise osv.except_osv(_('Error !'), _('Please define invoice sequence on invoice journal')) if not inv.invoice_line: raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.')) if inv.move_id: continue
cr.execute('SELECT id, type, number, move_id, reference ' \ 'FROM account_invoice ' \ 'WHERE id IN %s', (tuple(ids),)) obj_inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall():
for obj_inv in self.browse(cr, uid, ids): id = obj_inv.id invtype = obj_inv.type number = obj_inv.number move_id = obj_inv.move_id and obj_inv.move_id.id or False reference = obj_inv.reference
def action_number(self, cr, uid, ids, *args): cr.execute('SELECT id, type, number, move_id, reference ' \ 'FROM account_invoice ' \ 'WHERE id IN %s', (tuple(ids),)) obj_inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: if obj_inv.journal_id.invoice_sequence_id: sid = obj_inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id}) else: number = self.pool.get('ir.sequence').get(cr, uid, 'account.invoice.' + invtype) if invtype in ('in_invoice', 'in_refund'): ref = reference else: ref = self._convert_ref(cr, uid, number) cr.execute('UPDATE account_invoice SET number=%s ' \ 'WHERE id=%s', (number, id)) cr.execute('UPDATE account_move SET ref=%s ' \ 'WHERE id=%s AND (ref is null OR ref = \'\')', (ref, move_id)) cr.execute('UPDATE account_move_line SET ref=%s ' \ 'WHERE move_id=%s AND (ref is null OR ref = \'\')', (ref, move_id)) cr.execute('UPDATE account_analytic_line SET ref=%s ' \ 'FROM account_move_line ' \ 'WHERE account_move_line.move_id = %s ' \ 'AND account_analytic_line.move_id = account_move_line.id', (ref, move_id)) return True
tools.pdf_utils.fill_pdf(tools.config['addons_path']+'/l10n_lu/wizard/2008_DECL_F_M10.pdf', '/tmp/output.pdf', result)
tools.pdf_utils.fill_pdf(addons.get_module_resource('l10n_lu','wizard', '2008_DECL_F_M10.pdf'), '/tmp/output.pdf', result)
def create(self, cr, uid, ids, datas, context=None):
count(*) as nbr, sum(planned_revenue) as amount_revenue, sum(planned_cost) as amount_costs, sum(planned_revenue*probability/100)::decimal(16,2) as amount_revenue_prob, avg(probability)::decimal(16,2) as probability,
count(*) as nbr,
def init(self, cr): tools.drop_view_if_exists(cr, 'project_issue_report') cr.execute(""" create or replace view project_issue_report as ( select min(c.id) as id, to_char(c.create_date, 'YYYY') as name, to_char(c.create_date, 'MM') as month, c.state, c.user_id, c.section_id, c.categ_id, c.stage_id, to_char(c.date_closed, 'YYYY/mm/dd') as date_closed, u.company_id as company_id, c.priority as priority, c.project_id as project_id, c.type_id as type_id, count(*) as nbr, sum(planned_revenue) as amount_revenue, sum(planned_cost) as amount_costs, sum(planned_revenue*probability/100)::decimal(16,2) as amount_revenue_prob, avg(probability)::decimal(16,2) as probability, to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close from project_issue c left join res_users u on (c.id = u.id) group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.state, c.user_id,c.section_id,c.categ_id,c.stage_id ,c.date_closed,u.company_id,c.priority,c.project_id,c.type_id )""")
_inherits = {'res.alarm': "alarm_id"}
_inherit = 'res.alarm'
def do_alarm_unlink(self, cr, uid, ids, model, context={}): alarm_obj = self.pool.get('calendar.alarm') ir_obj = self.pool.get('ir.model') model_id = ir_obj.search(cr, uid, [('model', '=', model)])[0] model_obj = self.pool.get(model) for datas in model_obj.browse(cr, uid, ids): alarm_ids = alarm_obj.search(cr, uid, [('model_id', '=', model_id), ('res_id', '=', datas.id)]) if alarm_ids and len(alarm_ids): alarm_obj.unlink(cr, uid, alarm_ids) cr.execute('Update %s set caldav_alarm_id=NULL, alarm_id=NULL\ where id=%s' % (model_obj._table, datas.id)) cr.commit() return True
if vals.has_key('alarm_id'):
if vals.has_key('alarm_id') or vals.has_key('caldav_alarm_id'):
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): if isinstance(ids, (str, int, long)): select = [ids] else: select = ids new_ids = [] for id in select: id = caldav_id2real_id(id) if not id in new_ids: new_ids.append(id) res = super(calendar_event, self).write(cr, uid, new_ids, vals, context=context) if vals.has_key('alarm_id'): alarm_obj = self.pool.get('res.alarm') alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date') return res
alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date')
context.update({'alarm_id': vals.get('alarm_id')}) alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date', context=context)
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): if isinstance(ids, (str, int, long)): select = [ids] else: select = ids new_ids = [] for id in select: id = caldav_id2real_id(id) if not id in new_ids: new_ids.append(id) res = super(calendar_event, self).write(cr, uid, new_ids, vals, context=context) if vals.has_key('alarm_id'): alarm_obj = self.pool.get('res.alarm') alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date') return res
r['amount'] = round(r['balance'] * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')) - total
r['amount'] = round(r.get('balance', 0.0) * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')) - total
def _compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): """ Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
r['amount'] = round(r['amount'] * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
r['amount'] = round(r.get('amount', 0.0) * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
def _compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): """ Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
response_re = response_re = re.compile("Are you coming\?.*\n*.*(YES|NO|MAYBE).*", re.UNICODE)
response_re = re.compile("Are you coming\?.*\n*.*(YES|NO|MAYBE).*", re.UNICODE)
def _lang_get(self, cr, uid, context={}): obj = self.pool.get('res.lang') ids = obj.search(cr, uid, []) res = obj.read(cr, uid, ids, ['code', 'name'], context) res = [((r['code']).replace('_', '-'), r['name']) for r in res] return res
if journal.type in journal_type and not journal.invoice_sequence_id: res_ids = date_pool.search(cr, uid, [('model','=','ir.sequence'), ('name','=',journal_seq.get(journal.type, 'sale'))]) inv_seq_id = date_pool.browse(cr, uid, res_ids[0]).res_id inv_seq_id res.update({ 'invoice_sequence_id':inv_seq_id })
def create_sequence(self, cr, uid, ids, context={}): """ Create new entry sequence for every new Joural @param cr: cursor to database @param user: id of current user @param ids: list of record ids to be process @param context: context arguments, like lang, time zone @return: return a result """
invoice = context.get('invoice')
invoice = context.get('invoice', False)
def post(self, cr, uid, ids, context=None): invoice = context.get('invoice') if self.validate(cr, uid, ids, context) and len(ids): for move in self.browse(cr, uid, ids): if move.name =='/': new_name = False journal = move.journal_id if invoice.internal_number: new_name = invoice.internal_number else: if journal.sequence_id: c = {'fiscalyear_id': move.period_id.fiscalyear_id.id} new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id, context=c) else: raise osv.except_osv(_('Error'), _('No sequence defined in the journal !'))
if invoice.internal_number:
if invoice and invoice.internal_number:
def post(self, cr, uid, ids, context=None): invoice = context.get('invoice') if self.validate(cr, uid, ids, context) and len(ids): for move in self.browse(cr, uid, ids): if move.name =='/': new_name = False journal = move.journal_id if invoice.internal_number: new_name = invoice.internal_number else: if journal.sequence_id: c = {'fiscalyear_id': move.period_id.fiscalyear_id.id} new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id, context=c) else: raise osv.except_osv(_('Error'), _('No sequence defined in the journal !'))
'company_id': fields.related('shop_id','company_id',type='many2one',relation='res.company',string='Company',store=True)
'company_id': fields.related('shop_id','company_id',type='many2one',relation='res.company',string='Company',store=True, required=True)
def _get_order(self, cr, uid, ids, context=None): if context is None: context = {} result = {} for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context): result[line.order_id.id] = True return result.keys()
(sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average,
(sum(l.product_uom_qty*l.price_unit)/sum(nullif(l.product_uom_qty * u.factor,0))*count(l.product_id))::decimal(16,2) as price_average,
def init(self, cr): tools.drop_view_if_exists(cr, 'sale_report') cr.execute(""" create or replace view sale_report as ( select el.*, -- (select count(1) from sale_order_line where order_id = s.id) as nbr, (select 1) as nbr, s.date_order as date, s.date_confirm as date_confirm, to_char(s.date_order, 'YYYY') as year, to_char(s.date_order, 'MM') as month, to_char(s.date_order, 'YYYY-MM-DD') as day, s.partner_id as partner_id, s.user_id as user_id, s.shop_id as shop_id, s.company_id as company_id, extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay, s.state, s.shipped, s.shipped::integer as shipped_qty_1, s.pricelist_id as pricelist_id, s.project_id as analytic_account_id from sale_order s, ( select l.id as id, l.product_id as product_id, u.name as uom_name, sum(l.product_uom_qty * u.factor) as product_uom_qty, sum(l.product_uom_qty*l.price_unit) as price_total, (sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average, pt.categ_id, l.order_id from sale_order_line l left join product_uom u on (u.id=l.product_uom) left join product_template pt on (pt.id=l.product_id) group by l.id, l.order_id, l.product_id, u.name, pt.categ_id) el where s.id = el.order_id group by el.id, el.product_id, el.uom_name, el.product_uom_qty, el.price_total, el.price_average, el.categ_id, el.order_id, s.date_order, s.date_confirm, s.partner_id, s.user_id, s.shop_id, s.company_id, s.state, s.shipped, s.pricelist_id, s.project_id ) """)
account_id = False
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res
def write(self, cr, uid, ids, vals, context=None): if context is None: context = {} if 'date' in vals: new_vals = {} obj_hr_eval_iterview = self.pool.get('hr.evaluation.interview') current_record = self.browse(cr, uid, ids, context=context)[0] survey_requests = current_record.survey_request_ids new_vals.update({'date_deadline':vals.get('date')}) if survey_requests: for survey_req in survey_requests: obj_hr_eval_iterview.write(cr, uid, survey_req.id, new_vals,context=context) return super(hr_evaluation, self).write(cr, uid, ids, vals, context=context)
def button_cancel(self, cr, uid, ids, context=None): if context is None: context = {} self.write(cr, uid, ids,{'state':'cancel'}, context=context) return True
'code': wc.code
'ref': wc.code, 'product_id': wc.product_id.id, 'unit_amount': wc.costs_hour * wc.time_cycle, 'product_uom_id': wc.product_id.uom_id.id
def _costs_generate(self, cr, uid, production): """ Calculates total costs at the end of the production. @param production: Id of production order. @return: Calculated amount. """ amount = 0.0 analytic_line_obj = self.pool.get('account.analytic.line') for wc_line in production.workcenter_lines: wc = wc_line.workcenter_id if wc.costs_journal_id and wc.costs_general_account_id: value = wc_line.hour * wc.costs_hour account = wc.costs_hour_account_id.id if value and account: amount += value analytic_line_obj.create(cr, uid, { 'name': wc_line.name + ' (H)', 'amount': value, 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, 'code': wc.code } ) if wc.costs_journal_id and wc.costs_general_account_id: value = wc_line.cycle * wc.costs_cycle account = wc.costs_cycle_account_id.id if value and account: amount += value analytic_line_obj.create(cr, uid, { 'name': wc_line.name+' (C)', 'amount': value, 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, 'code': wc.code, } ) return amount
'code': wc.code,
'ref': wc.code, 'product_id': wc.product_id.id, 'unit_amount': wc.costs_hour * wc.time_cycle, 'product_uom_id': wc.product_id.uom_id.id
def _costs_generate(self, cr, uid, production): """ Calculates total costs at the end of the production. @param production: Id of production order. @return: Calculated amount. """ amount = 0.0 analytic_line_obj = self.pool.get('account.analytic.line') for wc_line in production.workcenter_lines: wc = wc_line.workcenter_id if wc.costs_journal_id and wc.costs_general_account_id: value = wc_line.hour * wc.costs_hour account = wc.costs_hour_account_id.id if value and account: amount += value analytic_line_obj.create(cr, uid, { 'name': wc_line.name + ' (H)', 'amount': value, 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, 'code': wc.code } ) if wc.costs_journal_id and wc.costs_general_account_id: value = wc_line.cycle * wc.costs_cycle account = wc.costs_cycle_account_id.id if value and account: amount += value analytic_line_obj.create(cr, uid, { 'name': wc_line.name+' (C)', 'amount': value, 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, 'code': wc.code, } ) return amount
return dict([(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)])
return [(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)]
def name_get(self, cr, uid, ids, context=None): return dict([(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)])
@param details: Description, Ddtails of case history if any
@param details: Description, Details of case history if any
def history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, \ email_from=False, message_id=False, references=None, attach=None, email_cc=None, \ email_bcc=None, email_date=None, context=None): """ @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param cases: a browse record list @param keyword: Case action keyword e.g.: If case is closed "Close" keyword is used @param history: Value True/False, If True it makes entry in case History otherwise in Case Log @param email: Email-To / Recipient address @param email_from: Email From / Sender address if any @param email_cc: Comma-Separated list of Carbon Copy Emails To addresse if any @param email_bcc: Comma-Separated list of Blind Carbon Copy Emails To addresses if any @param email_date: Email Date string if different from now, in server Timezone @param details: Description, Ddtails of case history if any @param atach: Attachment sent in email @param context: A standard dictionary for contextual values""" if context is None: context = {} if attach is None: attach = []
'partner_id': fields.related('picking_id','address_id','partner_id',type='many2one', relation="res.partner", string="Partner"),
'partner_id': fields.related('picking_id','address_id','partner_id',type='many2one', relation="res.partner", string="Partner", store=True),
def _check_product_lot(self, cr, uid, ids): """ Checks whether move is done or not and production lot is assigned to that move. @return: True or False """ for move in self.browse(cr, uid, ids): if move.prodlot_id and move.state == 'done' and (move.prodlot_id.product_id.id != move.product_id.id): return False return True
if context.get('active_model','') in ['res.partner']: partner = self.pool.get(context['active_model']).read(cr,uid,context['active_ids'],['supplier','customer'])[0]
if context is None: context = {} if context.get('active_model', '') in ['res.partner'] and context.get('active_ids', False) and context['active_ids']: partner = self.pool.get(context['active_model']).read(cr, uid, context['active_ids'], ['supplier','customer'])[0]
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False): journal_obj = self.pool.get('account.journal') if context.get('active_model','') in ['res.partner']: partner = self.pool.get(context['active_model']).read(cr,uid,context['active_ids'],['supplier','customer'])[0] if not view_type: view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name','=','account.invoice.tree')])[0] view_type = 'tree' if view_type == 'form': if partner['supplier'] and not partner['customer']: view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name','=','account.invoice.supplier.form')])[0] else: view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name','=','account.invoice.form')])[0] res = super(account_invoice,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) type = context.get('journal_type', 'sale') for field in res['fields']: if field == 'journal_id': journal_select = journal_obj._name_search(cr, uid, '', [('type', '=', type)], context=context, limit=None, name_get_uid=1) res['fields'][field]['selection'] = journal_select
'description': body['body'],
def msg_user(self, msg, id): body = self.msg_body_get(msg)
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], body['body'])
def msg_user(self, msg, id): body = self.msg_body_get(msg)
body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n'))) data = { 'description':body, } self.rpc(self.model, 'write', [id], data)
def msg_partner(self, msg, id): message = self.msg_body_get(msg) body = message['body'] act = 'case_open' self.rpc(self.model, act, [id]) body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n'))) data = { 'description':body, } self.rpc(self.model, 'write', [id], data) self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body']) return id
except ExceptionNoTb:
except security.ExceptionNoTb:
def check(self, db, uid, passwd): try: return super(users,self).check(db, uid, passwd) except ExceptionNoTb: # AccessDenied pass cr = pooler.get_db(db).cursor() user = self.browse(cr, 1, uid) logger = logging.getLogger('orm.ldap') if user and user.company_id.ldaps: for res_company_ldap in user.company_id.ldaps: try: l = ldap.open(res_company_ldap.ldap_server, res_company_ldap.ldap_server_port) if l.simple_bind_s(res_company_ldap.ldap_binddn, res_company_ldap.ldap_password): base = res_company_ldap.ldap_base scope = ldap.SCOPE_SUBTREE filter = filter_format(res_company_ldap.ldap_filter, (user.login,)) retrieve_attributes = None result_id = l.search(base, scope, filter, retrieve_attributes) timeout = 60 result_type, result_data = l.result(result_id, timeout) if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1: dn = result_data[0][0] if l.bind_s(dn, passwd): l.unbind() self._uid_cache.setdefault(db, {})[uid] = passwd cr.close() return True l.unbind() except Exception, e: logger.warning('cannot check', exc_info=True) pass cr.close() raise security.ExceptionNoTb('AccessDenied')
if form['qty'+str(i)] > 0 and form['qty'+str(i)] not in vals.values(): vals['qty'+str(qtys)] = form['qty'+str(i)] qtys += 1
vals['qty'+str(qtys)] = form['qty'+str(i)] qtys += 1
def _get_titles(self,form): lst = [] vals = {} qtys = 1
else: self.quantity.append(0)
def _set_quantity(self,form): for i in range(1,6): q = 'qty%d'%i if form[q] >0 and form[q] not in self.quantity: self.quantity.append(form[q])
val['qty'+str(i)] = ""
val['qty'+str(i)] = 0.0
def _get_categories(self, products,form): cat_ids=[] res=[] self.pricelist = form['price_list'] self._set_quantity(form) pool = pooler.get_pool(self.cr.dbname) pro_ids=[] for product in products: pro_ids.append(product.id) if product.categ_id.id not in cat_ids: cat_ids.append(product.categ_id.id) cats = pool.get('product.category').read(self.cr, self.uid, cat_ids, ['name']) for cat in cats: product_ids=pool.get('product.product').search(self.cr, self.uid, [('id','in',pro_ids),('categ_id','=',cat['id'])]) products = [] for product in pool.get('product.product').read(self.cr, self.uid, product_ids, ['name','code']): val={ 'id':product['id'], 'name':product['name'], 'code':product['code'] } i = 1 for qty in self.quantity: if qty == 0: val['qty'+str(i)] = "" else: val['qty'+str(i)]=self._get_price(self.pricelist, product['id'], qty) i += 1 products.append(val) res.append({'name':cat['name'],'products':products}) return res
period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])[0]['date_start'] period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])[0]['date_stop']
period_obj = self.pool.get('account.period') period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start'] period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop']
def _build_context(self, cr, uid, ids, data, context = None): result = {} result['fiscalyear'] = data['form']['fiscalyear_id'] and data['form']['fiscalyear_id'] or False if data['form']['filter'] == 'filter_date': result['date_from'] = data['form']['date_from'] result['date_to'] = data['form']['date_to'] elif data['form']['filter'] == 'filter_period': period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])[0]['date_start'] period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])[0]['date_stop'] cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) result['periods'] = lambda x: x[0], cr.fetchall() return result
res.update({'product_qty': move.product_qty.id})
res.update({'product_qty': move.product_qty})
def default_get(self, cr, uid, fields, context=None): """ Get default values @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param fields: List of fields for default value @param context: A standard dictionary @return: default values of fields """ res = super(stock_move_consume, self).default_get(cr, uid, fields, context=context) move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context) if 'product_id' in fields: res.update({'product_id': move.product_id.id}) if 'product_uom' in fields: res.update({'product_uom': move.product_uom.id}) if 'product_qty' in fields: res.update({'product_qty': move.product_qty.id}) if 'location_id' in fields: res.update({'location_id': move.location_id.id}) return res
if app_acc_in.company_id.id != company_id and app_acc_exp.company_id.id != company_id:
if app_acc_in and app_acc_in.company_id.id != company_id and app_acc_exp and app_acc_exp.company_id.id != company_id:
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): if context is None: context = {} company_id = context.get('company_id',False) if not partner_id: raise osv.except_osv(_('No Partner Defined !'),_("You must first select a partner !") ) if not product: if type in ('in_invoice', 'in_refund'): return {'value': {'categ_id': False}, 'domain':{'product_uom':[]}} else: return {'value': {'price_unit': 0.0, 'categ_id': False}, 'domain':{'product_uom':[]}} part = self.pool.get('res.partner').browse(cr, uid, partner_id) fpos_obj = self.pool.get('account.fiscal.position') fpos = fposition_id and fpos_obj.browse(cr, uid, fposition_id) or False
res = super(stock_move, self)._auto_init(cursor, context=contexts)
res = super(stock_move, self)._auto_init(cursor, context=context)
def _auto_init(self, cursor, context=None): res = super(stock_move, self)._auto_init(cursor, context=contexts) cursor.execute('SELECT indexname \ FROM pg_indexes \ WHERE indexname = \'stock_move_location_id_location_dest_id_product_id_state\'') if not cursor.fetchone(): cursor.execute('CREATE INDEX stock_move_location_id_location_dest_id_product_id_state \ ON stock_move (location_id, location_dest_id, product_id, state)') cursor.commit() return res
location_obj = self.pool.get('stock.location')
def action_move_create(self, cr, uid, ids,context=None): proc_obj = self.pool.get('procurement.order') move_obj = self.pool.get('stock.move') location_obj = self.pool.get('stock.location') picking_obj=self.pool.get('stock.picking') wf_service = netsvc.LocalService("workflow") for proc in proc_obj.browse(cr, uid, ids, context=context): line = None for line in proc.product_id.flow_pull_ids: if line.location_id==proc.location_id: break assert line, 'Line can not be False if we are on this state of the workflow' origin = (proc.origin or proc.name or '').split(':')[0] +':'+line.name picking_id =picking_obj.create(cr, uid, { 'origin': origin, 'company_id': line.company_id and line.company_id.id or False, 'type': line.picking_type, 'stock_journal_id': line.journal_id and line.journal_id.id or False, 'move_type': 'one', 'address_id': line.partner_address_id.id, 'note': line.name, # TODO: note on procurement ? 'invoice_state': line.invoice_state, }) move_id =move_obj.create(cr, uid, { 'name': line.name, 'picking_id': picking_id, 'company_id': line.company_id and line.company_id.id or False, 'product_id': proc.product_id.id, 'date': proc.date_planned, 'product_qty': proc.product_qty, 'product_uom': proc.product_uom.id, 'product_uos_qty': (proc.product_uos and proc.product_uos_qty)\ or proc.product_qty, 'product_uos': (proc.product_uos and proc.product_uos.id)\ or proc.product_uom.id, 'address_id': line.partner_address_id.id, 'location_id': line.location_src_id.id, 'location_dest_id': line.location_id.id, 'move_dest_id': proc.move_id and proc.move_id.id or False, # to verif, about history ? 'tracking_id': False, 'cancel_cascade': line.cancel_cascade, 'state': 'confirmed', 'note': line.name, # TODO: same as above }) if proc.move_id and proc.move_id.state in ('confirmed'): move_obj.write(cr,uid, [proc.move_id.id], { 'state':'waiting' }, context=context) proc_id = proc_obj.create(cr, uid, { 'name': line.name, 'origin': origin, 'company_id': line.company_id and line.company_id.id or False, 'date_planned': proc.date_planned, 'product_id': proc.product_id.id, 'product_qty': proc.product_qty, 'product_uom': proc.product_uom.id, 'product_uos_qty': (proc.product_uos and proc.product_uos_qty)\ or proc.product_qty, 'product_uos': (proc.product_uos and proc.product_uos.id)\ or proc.product_uom.id, 'location_id': line.location_src_id.id, 'procure_method': line.procure_method, 'move_id': move_id, }) wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) if proc.move_id: move_obj.write(cr, uid, [proc.move_id.id], {'location_id':proc.location_id.id})
self.write(cr, uid, id, {'history':history or '' + "\n" + time.strftime("%Y-%m-%d %H:%M:%S") + ": " + tools.ustr(message)}, context)
self.write(cr, uid, id, {'history': (history or '' )+ "\n" + time.strftime("%Y-%m-%d %H:%M:%S") + ": " + tools.ustr(message)}, context)
def historise(self, cr, uid, ids, message='', context=None): for id in ids: history = self.read(cr, uid, id, ['history'], context).get('history', '') self.write(cr, uid, id, {'history':history or '' + "\n" + time.strftime("%Y-%m-%d %H:%M:%S") + ": " + tools.ustr(message)}, context)
case_obj.write(cr, uid, case.id, {'ref': 'sale.order,%s' % new_id})
case_obj.write(cr, uid, [case.id], {'ref': 'sale.order,%s' % new_id})
def _makeOrder(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) case_obj = pool.get('crm.case') sale_obj = pool.get('sale.order') partner_obj = pool.get('res.partner') sale_line_obj = pool.get('sale.order.line')
self.write(cr, uid, ids, {'state':'done'}, context=context)
self.write(cr, uid, ids, {'state':'close'}, context=context)
def set_done(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {'state':'done'}, context=context) return True
cr.execute('update project_task set active=True where project_id in ('+','.join(map(str, ids))+')')
if ids: cr.execute('update project_task set active=True where project_id in ('+','.join(map(str, ids))+')')
def copy(self, cr, uid, id, default={},context={}): proj = self.browse(cr, uid, id, context=context) default = default or {} context['active_test'] = False default['state'] = 'open' if not default.get('name', False): default['name'] = proj.name+_(' (copy)') res = super(project, self).copy(cr, uid, id, default, context) ids = self.search(cr, uid, [('parent_id','child_of', [res])]) cr.execute('update project_task set active=True where project_id in ('+','.join(map(str, ids))+')') return res
cr.execute('select id from project_project where parent_id=%s', (proj.id,)) res = cr.fetchall() project_ids = [x[0] for x in res] for child in project_ids: self.duplicate_template(cr, uid, [child],context={'parent_id':new_id})
child_ids = self.search(cr, uid, [('parent_id','=', proj.id)]) if child_ids: self.duplicate_template(cr, uid, child_ids, context={'parent_id':new_id})
def duplicate_template(self, cr, uid, ids,context={}): for proj in self.browse(cr, uid, ids): parent_id=context.get('parent_id',False) new_id=self.pool.get('project.project').copy(cr, uid, proj.id,default={'name':proj.name+_(' (copy)'),'state':'open','parent_id':parent_id}) cr.execute('select id from project_task where project_id=%s', (proj.id,)) res = cr.fetchall() for (tasks_id,) in res: self.pool.get('project.task').copy(cr, uid, tasks_id,default={'project_id':new_id,'active':True}, context=context) cr.execute('select id from project_project where parent_id=%s', (proj.id,)) res = cr.fetchall() project_ids = [x[0] for x in res] for child in project_ids: self.duplicate_template(cr, uid, [child],context={'parent_id':new_id})
cr.execute('select id from project_project where parent_id=%s', (proj.id,)) project_ids = [x[0] for x in cr.fetchall()] for child in project_ids: self.setActive(cr, uid, [child], value, context)
child_ids = self.search(cr, uid, [('parent_id','=', proj.id)]) if child_ids: self.setActive(cr, uid, child_ids, value, context)
def setActive(self, cr, uid, ids, value=True, context={}): for proj in self.browse(cr, uid, ids, context): self.write(cr, uid, [proj.id], {'state': value and 'open' or 'template'}, context) cr.execute('select id from project_task where project_id=%s', (proj.id,)) tasks_id = [x[0] for x in cr.fetchall()] if tasks_id: self.pool.get('project.task').write(cr, uid, tasks_id, {'active': value}, context) cr.execute('select id from project_project where parent_id=%s', (proj.id,)) project_ids = [x[0] for x in cr.fetchall()] for child in project_ids: self.setActive(cr, uid, [child], value, context) return True
if not line.sequence: account_bank_statement_line_obj.write(cr, uid, [line.id], {'sequence': seq}, context=context)
account_bank_statement_line_obj.write(cr, uid, [line.id], {'sequence': seq}, context=context)
def write(self, cr, uid, ids, vals, context=None): res = super(account_bank_statement, self).write(cr, uid, ids, vals, context=context) account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') for statement in self.browse(cr, uid, ids, context): seq = 0 for line in statement.line_ids: seq += 1 if not line.sequence: account_bank_statement_line_obj.write(cr, uid, [line.id], {'sequence': seq}, context=context) return res
return st_number + ' - ' + str(st_line.sequence)
return st_number + '/' + str(st_line.sequence)
def get_next_st_line_number(self, cr, uid, st_number, st_line, context=None): return st_number + ' - ' + str(st_line.sequence)
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None):
def onchange_type(self, cr, uid, line_id, partner_id, type, context=None):
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res_users_obj = self.pool.get('res.users') res_currency_obj = self.pool.get('res.currency') res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res account_id = False line = self.browse(cursor, user, line_id) if not line or (line and not line[0].account_id): part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id
line = self.browse(cursor, user, line_id)
line = self.browse(cr, uid, line_id)
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res_users_obj = self.pool.get('res.users') res_currency_obj = self.pool.get('res.currency') res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res account_id = False line = self.browse(cursor, user, line_id) if not line or (line and not line[0].account_id): part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id
part = obj_partner.browse(cursor, user, partner_id, context=context)
part = obj_partner.browse(cr, uid, partner_id, context=context)
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res_users_obj = self.pool.get('res.users') res_currency_obj = self.pool.get('res.currency') res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res account_id = False line = self.browse(cursor, user, line_id) if not line or (line and not line[0].account_id): part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id
if account_id and (not line or (line and not line[0].amount)) and not context.get('amount', False): company_currency_id = res_users_obj.browse(cursor, user, user, context=context).company_id.currency_id.id if not currency_id: currency_id = company_currency_id cursor.execute('SELECT sum(debit-credit) \ FROM account_move_line \ WHERE (reconcile_id is null) \ AND partner_id = %s \ AND account_id=%s', (partner_id, account_id)) pgres = cursor.fetchone() balance = pgres and pgres[0] or 0.0 balance = res_currency_obj.compute(cursor, user, company_currency_id, currency_id, balance, context=context) res['value']['amount'] = balance
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res_users_obj = self.pool.get('res.users') res_currency_obj = self.pool.get('res.currency') res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res account_id = False line = self.browse(cursor, user, line_id) if not line or (line and not line[0].account_id): part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id
'name': fields.char('Name', size=64, required=True),
'name': fields.char('Communication', size=64, required=True),
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res_users_obj = self.pool.get('res.users') res_currency_obj = self.pool.get('res.currency') res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: context = {} if not partner_id: return res account_id = False line = self.browse(cursor, user, line_id) if not line or (line and not line[0].account_id): part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id