rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
to_char(create_date, 'MM'), create_uid
to_char(create_date, 'MM')
def init(self, cr): tools.sql.drop_view_if_exists(cr, 'purchase_order_qty_amount') cr.execute(""" create or replace view purchase_order_qty_amount as ( select min(id) as id, to_char(create_date, 'MM') as month, sum(product_qty) as total_qty, create_uid as user_id, sum(price_unit*product_qty) as total_amount from purchase_order_line where to_char(create_date,'YYYY') = to_char(current_date,'YYYY') group by to_char(create_date, 'MM'), create_uid
if not slip.employee_id.contract_id:
update = {} ttyme = datetime.fromtimestamp(time.mktime(time.strptime(slip.date,"%Y-%m-%d"))) contracts = self.get_contract(cr, uid, slip.employee_id, date, context) if contracts.get('id', False) == False: update.update({ 'basic': round(0.0), 'basic_before_leaves': round(0.0), 'name':'Salary Slip of %s for %s' % (slip.employee_id.name, ttyme.strftime('%B-%Y')), 'state':'draft', 'contract_id':False, 'company_id':slip.employee_id.company_id.id }) self.write(cr, uid, [slip.id], update, context=context)
def get_days(start, end, month, year, calc_day): count = 0 import datetime for day in range(start, end): if datetime.date(year, month, day).weekday() == calc_day: count += 1 return count
update = {}
def get_days(start, end, month, year, calc_day): count = 0 import datetime for day in range(start, end): if datetime.date(year, month, day).weekday() == calc_day: count += 1 return count
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(slip.date,"%Y-%m-%d")))
def get_days(start, end, month, year, calc_day): count = 0 import datetime for day in range(start, end): if datetime.date(year, month, day).weekday() == calc_day: count += 1 return count
if not slip.employee_id.contract_id:
if not slip.contract_id:
def get_days(start, end, month, year, calc_day): count = 0 import datetime for day in range(start, end): if datetime.date(year, month, day).weekday() == calc_day: count += 1 return count
help="Check this box if you want to print all entries when printing the General Ledger, "\ "otherwise it will only print its balance."),
def _get_level(self, cr, uid, ids, field_name, arg, context={}): res={} accounts = self.browse(cr, uid, ids) for account in accounts: level = 0 if account.parent_id : obj = self.browse(cr, uid, account.parent_id.id) level = obj.level + 1 res[account.id] = level return res
'name': reg.invoice_label + '-' + reg.name,
'name': reg.invoice_label + '-' + c_name,
def _makeInvoices(self, cr, uid, context={}): invoices = {} invoice_ids = [] create_ids=[] tax_ids=[] inv_create = 0 inv_reject = 0 inv_rej_reason = "" list_inv = [] obj_event_reg = self.pool.get('event.registration') obj_lines = self.pool.get('account.invoice.line') inv_obj = self.pool.get('account.invoice') data_event_reg = obj_event_reg.browse(cr,uid, context['active_ids'], context=context)
acc_id = obj_task.project_id.analytic_account_id.id vals_line['account_id'] = acc_id res = obj_timesheet.on_change_account_id(cr, uid, False, acc_id) if res.get('value'): vals_line.update(res['value']) vals_line['general_account_id'] = result['general_account_id'] vals_line['journal_id'] = result['journal_id'] vals_line['amount'] = 0.0 vals_line['product_uom_id'] = result['product_uom_id'] amount = vals_line['unit_amount'] prod_id = vals_line['product_id'] unit = False timeline_id = obj_timesheet.create(cr, uid, vals=vals_line, context=context) amount_unit = obj_timesheet.on_change_unit_amount(cr, uid, timeline_id, prod_id, amount, False, unit, context=context) if amount_unit and 'amount' in amount_unit.get('value',{}): updv = { 'amount': amount_unit['value']['amount'] } obj_timesheet.write(cr, uid, [timeline_id], updv, context=context) vals['hr_analytic_timesheet_id'] = timeline_id
acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False if acc_id: vals_line['account_id'] = acc_id res = obj_timesheet.on_change_account_id(cr, uid, False, acc_id) if res.get('value'): vals_line.update(res['value']) vals_line['general_account_id'] = result['general_account_id'] vals_line['journal_id'] = result['journal_id'] vals_line['amount'] = 0.0 vals_line['product_uom_id'] = result['product_uom_id'] amount = vals_line['unit_amount'] prod_id = vals_line['product_id'] unit = False timeline_id = obj_timesheet.create(cr, uid, vals=vals_line, context=context) amount_unit = obj_timesheet.on_change_unit_amount(cr, uid, timeline_id, prod_id, amount, False, unit, context=context) if amount_unit and 'amount' in amount_unit.get('value',{}): updv = { 'amount': amount_unit['value']['amount'] } obj_timesheet.write(cr, uid, [timeline_id], updv, context=context) vals['hr_analytic_timesheet_id'] = timeline_id
def create(self, cr, uid, vals, *args, **kwargs): obj_timesheet = self.pool.get('hr.analytic.timesheet') project_obj = self.pool.get('project.project') task_obj = self.pool.get('project.task') uom_obj = self.pool.get('product.uom') vals_line = {} context = kwargs.get('context', {}) #TOFIX: after loading project_timesheet module, it's fail yml of other project* modules. #Temporary: pass context['withoutemployee'] = True in all yml. if 'withoutemployee' in context and context['withoutemployee']: return super(project_work,self).create(cr, uid, vals, context=context) obj_task = task_obj.browse(cr, uid, vals['task_id']) result = self.get_user_related_details(cr, uid, vals.get('user_id', uid)) vals_line['name'] = '%s: %s' % (tools.ustr(obj_task.name), tools.ustr(vals['name']) or '/') vals_line['user_id'] = vals['user_id'] vals_line['product_id'] = result['product_id'] vals_line['date'] = vals['date'][:10] #calculate quantity based on employee's product's uom vals_line['unit_amount'] = vals['hours'] user_uom, default_uom = project_obj._get_user_and_default_uom_ids(cr, uid) if result['product_uom_id'] != default_uom: vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id']) acc_id = obj_task.project_id.analytic_account_id.id vals_line['account_id'] = acc_id res = obj_timesheet.on_change_account_id(cr, uid, False, acc_id) if res.get('value'): vals_line.update(res['value']) vals_line['general_account_id'] = result['general_account_id'] vals_line['journal_id'] = result['journal_id'] vals_line['amount'] = 0.0 vals_line['product_uom_id'] = result['product_uom_id'] amount = vals_line['unit_amount'] prod_id = vals_line['product_id'] unit = False timeline_id = obj_timesheet.create(cr, uid, vals=vals_line, context=context)
WHERE (period_id = %s) AND (warehouse_id = %s)", (f.period_id2.id, f.warehouse_id2.id))
WHERE (period_id = %s) AND (warehouse_id = %s)", (f.period_id.id, f.warehouse_id.id))
def create_planning(self,cr, uid, ids, context=None): if context is None: context = {} product_obj = self.pool.get('product.product') planning_obj = self.pool.get('stock.planning') mod_obj = self.pool.get('ir.model.data') prod_categ_obj = self.pool.get('product.category') template_obj = self.pool.get('product.template') planning_lines = [] for f in self.browse(cr, uid, ids, context=context): if f.forecasted_products: cr.execute("SELECT product_id \ FROM stock_sale_forecast \ WHERE (period_id = %s) AND (warehouse_id = %s)", (f.period_id2.id, f.warehouse_id2.id)) products_id1 = [x for x, in cr.fetchall()] else: categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or [] prod_categ_ids = prod_categ_obj.search(cr,uid,[('parent_id','child_of',categ_ids)]) templates_ids = template_obj.search(cr,uid,[('categ_id','in',prod_categ_ids)]) products_id1 = product_obj.search(cr,uid,[('product_tmpl_id','in',templates_ids)]) if len(products_id1)==0: raise osv.except_osv(_('Error !'), _('No forecasts for selected period or no products in selected category !'))
def _amount_all(self, cr, uid, ids, field_name, arg, context):
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
def _amount_all(self, cr, uid, ids, field_name, arg, context): res = {} cur_obj=self.pool.get('res.currency') for order in self.browse(cr, uid, ids): res[order.id] = { 'amount_untaxed': 0.0, 'amount_tax': 0.0, 'amount_total': 0.0, } val = val1 = 0.0 cur=order.pricelist_id.currency_id for line in order.order_line: for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id.id, order.partner_id)['taxes']: val+= c['amount'] val1 += line.price_subtotal res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val) res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1) res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'] return res
val+= c['amount'] val1 += line.price_subtotal
val += c['amount']
def _amount_all(self, cr, uid, ids, field_name, arg, context): res = {} cur_obj=self.pool.get('res.currency') for order in self.browse(cr, uid, ids): res[order.id] = { 'amount_untaxed': 0.0, 'amount_tax': 0.0, 'amount_total': 0.0, } val = val1 = 0.0 cur=order.pricelist_id.currency_id for line in order.order_line: for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id.id, order.partner_id)['taxes']: val+= c['amount'] val1 += line.price_subtotal res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val) res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1) res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'] return res
refs = msg.get('references') references = refs.split()
refs = msg.get('references',False) references = False if refs: references = refs.split()
def search_message(self, cr, uid, message, context=None): #@param message: string of mail which is read from EML File #@return model,res_id references = [] dictcreate = dict(message) msg = dictcreate.get('message') msg = self.pool.get('email.server.tools').parse_message(msg) message_id = msg.get('message-id') refs = msg.get('references') references = refs.split() msg_pool = self.pool.get('mailgate.message') model = '' res_id = 0 if message_id: msg_ids = msg_pool.search(cr, uid, [('message_id','=',message_id)]) if msg_ids and len(msg_ids): msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id else: if references : msg_ids = msg_pool.search(cr, uid, [('message_id','in',references)]) msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id return (model,res_id)
msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id
if msg_ids and len(msg_ids): msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id
def search_message(self, cr, uid, message, context=None): #@param message: string of mail which is read from EML File #@return model,res_id references = [] dictcreate = dict(message) msg = dictcreate.get('message') msg = self.pool.get('email.server.tools').parse_message(msg) message_id = msg.get('message-id') refs = msg.get('references') references = refs.split() msg_pool = self.pool.get('mailgate.message') model = '' res_id = 0 if message_id: msg_ids = msg_pool.search(cr, uid, [('message_id','=',message_id)]) if msg_ids and len(msg_ids): msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id else: if references : msg_ids = msg_pool.search(cr, uid, [('message_id','in',references)]) msg = msg_pool.browse(cr, uid, msg_ids[0]) model = msg.model res_id = msg.res_id return (model,res_id)
bname,ext = os.path.splitext(filename)
try: bname,ext = os.path.splitext(filename or 'test.tmp') except Exception: bname, ext = filename, 'tmp'
def doIndex(self, content, filename=None, content_type=None, realfname = None, debug=False): fobj = None fname = None mime = None if content_type and self.mimes.has_key(content_type): mime = content_type fobj = self.mimes[content_type] elif filename: bname,ext = os.path.splitext(filename) if self.exts.has_key(ext): fobj = self.exts[ext] mime = fobj._getDefMime(ext) if content_type and not fobj: mime,fobj = mime_match(content_type, self.mimes) if not fobj: try: if realfname : fname = realfname else: bname,ext = os.path.splitext(filename) fd, fname = tempfile.mkstemp(suffix=ext) os.write(fd, content) os.close(fd) fp = Popen(['file','-b','--mime',fname], shell=False, stdout=PIPE).stdout result = fp.read() fp.close() mime2 = result.split(';')[0] self.__logger.debug('File gave us: %s', mime2) # Note that the temporary file still exists now. mime,fobj = mime_match(mime2, self.mimes) if not mime: mime = mime2 except Exception: self.__logger.exception('Cannot determine mime type') try: if fobj: res = (mime, fobj.indexContent(content,filename,fname or realfname) ) else: self.__logger.debug("Have no object, return (%s, None)", mime) res = (mime, None ) except Exception: self.__logger.exception("Could not index file %s (%s)", filename, fname or realfname) res = None # If we created a tmp file, unlink it now if not realfname and fname: try: os.unlink(fname) except Exception: self.__logger.exception("Could not unlink %s", fname) return res
can_compute = True for child in current.child_id: if child.id not in sums: can_compute = False try: brs.insert(0, brs.pop(brs.index(child))) except ValueError: brs.insert(0, child) if can_compute: brs.pop(0) for fn in field_names: sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0) if current.child_id: sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id)
brs.pop(0) for fn in field_names: sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0) if current.child_id: sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id)
def __compute(self, cr, uid, ids, field_names, arg=None, context=None, query='', query_params=()): """ compute the balance, debit and/or credit for the provided account ids Arguments: `ids`: account ids `field_names`: the fields to compute (a list of any of 'balance', 'debit' and 'credit') `arg`: unused fields.function stuff `query`: additional query filter (as a string) `query_params`: parameters for the provided query string (__compute will handle their escaping) as a tuple """ mapping = { 'balance': "COALESCE(SUM(l.debit),0) " \ "- COALESCE(SUM(l.credit), 0) as balance", 'debit': "COALESCE(SUM(l.debit), 0) as debit", 'credit': "COALESCE(SUM(l.credit), 0) as credit" } #get all the necessary accounts children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context) #compute for each account the balance/debit/credit from the move lines accounts = {} if children_and_consolidated: aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
"sale_tax": fields.many2one("account.tax.template", "Sale Tax"), "purchase_tax": fields.many2one("account.tax.template", "Purchase Tax"),
"sale_tax": fields.many2one("account.tax.template", "Default Sale Tax"), "purchase_tax": fields.many2one("account.tax.template", "Default Purchase Tax"),
def _default_company(self, cr, uid, context={}): user = self.pool.get('res.users').browse(cr, uid, uid, context=context) if user.company_id: return user.company_id.id return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id" , "=", chart_template_id)], order="sequence") if len(ids) > 0: id=ids[0] res['value']["sale_tax"] = id res['value']["purchase_tax"] = id
sale_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id" , "=", chart_template_id), ('type_tax_use', 'in', ('sale','all'))], order="sequence") purchase_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id" , "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all'))], order="sequence") res['value']["sale_tax"] = sale_tax_ids and sale_tax_ids[0] or False res['value']["purchase_tax"] = purchase_tax_ids and purchase_tax_ids[0] or False
def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None): res = {} res['value'] = {} res['value']["sale_tax"] = False res['value']["purchase_tax"] = False if chart_template_id: ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id" , "=", chart_template_id)], order="sequence") if len(ids) > 0: id=ids[0] res['value']["sale_tax"] = id res['value']["purchase_tax"] = id return res
return sequence + str(self.checksum(sequence))
try: return sequence + str(self.checksum(sequence)) except Exception, e: return sequence
def make_sscc(self, cr, uid, context=None): sequence = self.pool.get('ir.sequence').get(cr, uid, 'stock.lot.tracking') return sequence + str(self.checksum(sequence))
method=True, store=True, type='datetime', string='Expected Date', select=1, help="Expected date for the picking to be processed. Will be set to date of actual processing if not specified."),
method=True, store=True, type='datetime', string='Expected Date', select=1, help="Expected date for the picking to be processed"),
def create(self, cr, user, vals, context=None): if ('name' not in vals) or (vals.get('name')=='/'): seq_obj_name = 'stock.picking.' + vals['type'] vals['name'] = self.pool.get('ir.sequence').get(cr, user, seq_obj_name) new_id = super(stock_picking, self).create(cr, user, vals, context) return new_id
users_obj = self.pool.get('res.users')
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
prodlot_id = partial_data.get('prodlot_id',False)
prodlot_id = partial_data.get('prodlot_id') prodlot_ids[move.id] = prodlot_id
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
user = users_obj.browse(cr, uid, uid)
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
pricetype ='standard_price' if pricetype and qty > 0:
if qty > 0:
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
amount_unit = product.price_get(pricetype, context)[product.id]
amount_unit = product.price_get('standard_price', context)[product.id]
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
product_obj.write(cr, uid, [product.id], {pricetype.field: new_std_price})
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
new_obj = move_obj.copy(cr, uid, move.id, {
defaults = {
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
})
} prodlot_id = prodlot_ids[move.id] if prodlot_id: defaults.update(prodlot_id=prodlot_id) new_obj = move_obj.copy(cr, uid, move.id, defaults)
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
for move in too_many: product_qty = move_product_qty[move.id] move_obj.write(cr, uid, [move.id], { 'product_qty' : product_qty, 'product_uos_qty': product_qty, 'picking_id': new_picking, }) else: for move in too_many: product_qty = move_product_qty[move.id] move_obj.write(cr, uid, [move.id], { 'product_qty': product_qty, 'product_uos_qty': product_qty })
for move in complete: if prodlot_ids.get(move.id): move_obj.write(cr, uid, move.id, {'prodlot_id': prodlot_ids[move.id]}) for move in too_many: product_qty = move_product_qty[move.id] defaults = { 'product_qty' : product_qty, 'product_uos_qty': product_qty, } prodlot_id = prodlot_ids.get(move.id) if prodlot_ids.get(move.id): defaults.update(prodlot_id=prodlot_id) if new_picking: defaults.update(picking_id=new_picking) move_obj.write(cr, uid, [move.id], defaults)
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
if new_picking:
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ Makes partial picking 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 @return: Dictionary of values """ if context is None: context = {} else: context = dict(context) res = {} move_obj = self.pool.get('stock.move') 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) for pick in self.browse(cr, uid, ids, context=context): new_picking = None new_moves = [] complete, too_many, too_few = [], [], [] move_product_qty = {} for move in pick.move_lines: if move.state in ('done', 'cancel'): continue partial_data = partial_datas.get('move%s'%(move.id), False) assert partial_data, _('Do not Found Partial data of Stock Move Line :%s' %(move.id)) product_qty = partial_data.get('product_qty',0.0) move_product_qty[move.id] = product_qty product_uom = partial_data.get('product_uom',False) product_price = partial_data.get('product_price',0.0) product_currency = partial_data.get('product_currency',False) prodlot_id = partial_data.get('prodlot_id',False) if move.product_qty == product_qty: complete.append(move) elif move.product_qty > product_qty: too_few.append(move) else: too_many.append(move)
'date': fields.datetime('Date', required=True, help="Scheduled date for the movement of the products or real date if the move is done.", readonly=True), 'date_expected': fields.datetime('Date Expected', required=True, help="Scheduled date for the movement of the products"),
'date': fields.datetime('Date', required=True, help="Move date: scheduled date until move is done, then date of actual move processing", readonly=True), 'date_expected': fields.datetime('Scheduled Date', required=True, help="Scheduled date for the processing of this move"),
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
users_obj = self.pool.get('res.users')
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
prodlot_id = partial_data.get('prodlot_id',False)
prodlot_ids[move.id] = partial_data.get('prodlot_id')
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
user = users_obj.browse(cr, uid, uid) context['currency_id'] = move.company_id.currency_id.id
move_currency_id = move.company_id.currency_id.id context['currency_id'] = move_currency_id
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
user.company_id.currency_id.id, product_price)
move_currency_id, product_price)
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
new_move = self.copy(cr, uid, move.id, { 'product_qty' : product_qty, 'product_uos_qty': product_qty, 'picking_id' : move.picking_id.id, 'state': 'assigned', 'move_dest_id': False, 'price_unit': move.price_unit, })
defaults = { 'product_qty' : product_qty, 'product_uos_qty': product_qty, 'picking_id' : move.picking_id.id, 'state': 'assigned', 'move_dest_id': False, 'price_unit': move.price_unit, } prodlot_id = prodlot_ids[move.id] if prodlot_id: defaults.update(prodlot_id=prodlot_id) new_move = self.copy(cr, uid, move.id, defaults)
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
if prodlot_id: self.write(cr, uid, [move.id],{'prodlot_id': prodlot_id,})
if prodlot_ids.get(move.id): self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)})
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
ref = {} done_move_ids = [] for move in complete: done_move_ids.append(move.id) return done_move_ids
return [move.id for move in complete]
def do_partial(self, cr, uid, ids, partial_datas, context=None): """ 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) new_moves = []
select stock.create_date, min(stock.id) as id, sum(stock.product_qty) as qty, 0 as planned_qty
select stock.create_date as date, min(stock.id) as id, sum(stock.product_qty) as qty, 0 as planned_qty
def init(self, cr): tools.drop_view_if_exists(cr, 'report_delivery_products_planned') cr.execute(""" create or replace view report_delivery_products_planned as ( select stock.create_date, min(stock.id) as id, sum(stock.product_qty) as qty, 0 as planned_qty from stock_picking picking inner join stock_move stock on picking.id = stock.picking_id and picking.type = 'out' where stock.create_date between (select cast(date_trunc('week', current_date) as date)) and (select cast(date_trunc('week', current_date) as date) + 7) group by stock.create_date
select stock.date, min(stock.id), 0 as actual_qty, sum(stock.product_qty) as planned_qty
select stock.date as date, min(stock.id), 0 as actual_qty, sum(stock.product_qty) as planned_qty
def init(self, cr): tools.drop_view_if_exists(cr, 'report_delivery_products_planned') cr.execute(""" create or replace view report_delivery_products_planned as ( select stock.create_date, min(stock.id) as id, sum(stock.product_qty) as qty, 0 as planned_qty from stock_picking picking inner join stock_move stock on picking.id = stock.picking_id and picking.type = 'out' where stock.create_date between (select cast(date_trunc('week', current_date) as date)) and (select cast(date_trunc('week', current_date) as date) + 7) group by stock.create_date
if fil.parent_id: self.storage_id = fil.parent_id.storage_id.id else: self.storage_id = None
self.storage_id = None par = fil.parent_id while par: if par.storage_id and par.storage_id.id: self.storage_id = par.storage_id.id break par = par.parent_id
def __init__(self, path, parent, context, fil): super(node_file,self).__init__(path, parent,context) self.file_id = fil.id #todo: more info from ir_attachment if fil.file_type and '/' in fil.file_type: self.mimetype = str(fil.file_type) self.create_date = fil.create_date self.write_date = fil.write_date or fil.create_date self.content_length = fil.file_size self.displayname = fil.name # This only propagates the problem to get_data. Better # fix those files to point to the root dir. if fil.parent_id: self.storage_id = fil.parent_id.storage_id.id else: self.storage_id = None
return self._get_dav_props_hlpr(cr, nodes.node_dir,
return self._get_dav_props_hlpr(cr, nodes.node_file,
def get_dav_props(self, cr): return self._get_dav_props_hlpr(cr, nodes.node_dir, None, 'file_id', self.file_id) #'document.webdav.dir.property', 'dir_id', self.dir_id)
return self._get_dav_props_hlpr(cr, nodes.node_dir,
return self._get_dav_props_hlpr(cr, nodes.node_database,
def get_dav_props(self, cr): return self._get_dav_props_hlpr(cr, nodes.node_dir, 'document.webdav.dir.property', 'dir_id', False)
return self._get_dav_eprop_hlpr(cr, nodes.node_dir, ns, prop,
return self._get_dav_eprop_hlpr(cr, nodes.node_database, ns, prop,
def get_dav_eprop(self, cr, ns, prop): return self._get_dav_eprop_hlpr(cr, nodes.node_dir, ns, prop, 'document.webdav.dir.property', 'dir_id', False)
context.update({'lang': inv.partner_id.lang}) compute_taxes = ait_obj.compute(cr, uid, inv.id, context=context)
ctx = context.copy() ctx.update({'lang': inv.partner_id.lang}) compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx)
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.sequence_id: raise osv.except_osv(_('Error !'), _('Please define 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
print "formmmmmmmmmm", form
def get_fiscalyear(self,form): print "formmmmmmmmmm", form return pooler.get_pool(self.cr.dbname).get('account.fiscalyear').browse(self.cr,self.uid,form['fiscalyear_id']).name
return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_from']).name
if form['filter'] == 'filter_period': if form['period_from']: return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_from']).name return ''
def get_start_period(self, form): return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_from']).name
return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_to']).name
if form['filter'] == 'filter_period': if form['period_to']: return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_to']).name return ''
def get_end_period(self, form): return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_to']).name
obj=[]
def write(self, cr, uid, ids, vals, context=None): obj=[] if 'company_id' in vals: move_lines = self.pool.get('account.move.line').search(cr, uid, [('journal_id', 'in', ids)]) if move_lines: raise osv.except_osv(_('Warning !'), _('You cannot modify company of this journal as its related record exist in Entry Lines')) return super(account_journal, self).write(cr, uid, ids, vals, context=context)
journal_type = ('sale', 'sale_refund', 'purchase', 'purchase_refund') journal_seq = { 'sale':'seq_out_invoice', 'purchase':'seq_in_invoice', 'purchase_refund':'seq_out_refund', 'sale_refund':'seq_in_refund' }
def create_sequence(self, cr, uid, vals, context=None): """ 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 """
date_pool = self.pool.get('ir.model.data') result = True
def create_sequence(self, cr, uid, vals, context=None): """ 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 """
obj=[]
def write(self, cr, uid, ids, vals, context={}): obj=[] if 'company_id' in vals: move_lines = self.pool.get('account.move.line').search(cr, uid, [('period_id', 'in', ids)]) if move_lines: raise osv.except_osv(_('Warning !'), _('You cannot modify company of this period as its related record exist in Entry Lines')) return super(account_period, self).write(cr, uid, ids, vals, context=context)
new_account = acc_obj.create(cr, uid, vals)
acc_obj.create(cr, uid, vals)
def action_create(self,cr,uid,ids,context=None): acc_obj = self.pool.get('account.account') tmpl_obj = self.pool.get('account.account.template') data = self.read(cr, uid, ids) company_id = acc_obj.read(cr, uid, [data[0]['cparent_id']], ['company_id'])[0]['company_id'][0] account_template = tmpl_obj.browse(cr, uid, context['tmpl_ids']) vals = { 'name': account_template.name, 'currency_id': account_template.currency_id and account_template.currency_id.id or False, 'code': account_template.code, 'type': account_template.type, 'user_type': account_template.user_type and account_template.user_type.id or False, 'reconcile': account_template.reconcile, 'shortcut': account_template.shortcut, 'note': account_template.note, 'parent_id': data[0]['cparent_id'], 'company_id': company_id, } new_account = acc_obj.create(cr, uid, vals) return {'type':'state', 'state': 'end' }
except Exception,e:
except:
def execute(self, cr, uid, ids, context=None): obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') obj_acc_tax = self.pool.get('account.tax') obj_journal = self.pool.get('account.journal') obj_sequence = self.pool.get('ir.sequence') obj_acc_template = self.pool.get('account.account.template') obj_fiscal_position_template = self.pool.get('account.fiscal.position.template') obj_fiscal_position = self.pool.get('account.fiscal.position') data_pool = self.pool.get('ir.model.data') analytic_journal_obj = self.pool.get('account.analytic.journal')
case when uom.category_id != puom.category_id then pt.weight_net * inv_line.quantity else case when uom.factor_inv_data > 0 then pt.weight_net * inv_line.quantity * uom.factor_inv_data else pt.weight_net * inv_line.quantity / uom.factor end end
case when uom.category_id != puom.category_id then (pt.weight_net * inv_line.quantity) else (pt.weight_net * inv_line.quantity * uom.factor) end
def init(self, cr): drop_view_if_exists(cr, 'report_intrastat') cr.execute(""" create or replace view report_intrastat as ( select to_char(inv.create_date, 'YYYY') as name, to_char(inv.create_date, 'MM') as month, min(inv_line.id) as id, intrastat.id as intrastat_id, upper(inv_country.code) as code, sum(case when inv_line.price_unit is not null then inv_line.price_unit * inv_line.quantity else 0 end) as value, sum( case when uom.category_id != puom.category_id then pt.weight_net * inv_line.quantity else case when uom.factor_inv_data > 0 then pt.weight_net * inv_line.quantity * uom.factor_inv_data else pt.weight_net * inv_line.quantity / uom.factor end end ) as weight, sum( case when uom.category_id != puom.category_id then inv_line.quantity else case when uom.factor_inv_data > 0 then inv_line.quantity * uom.factor_inv_data else inv_line.quantity / uom.factor end end ) as supply_units,
else case when uom.factor_inv_data > 0 then inv_line.quantity * uom.factor_inv_data else inv_line.quantity / uom.factor end end
else (inv_line.quantity * uom.factor) end
def init(self, cr): drop_view_if_exists(cr, 'report_intrastat') cr.execute(""" create or replace view report_intrastat as ( select to_char(inv.create_date, 'YYYY') as name, to_char(inv.create_date, 'MM') as month, min(inv_line.id) as id, intrastat.id as intrastat_id, upper(inv_country.code) as code, sum(case when inv_line.price_unit is not null then inv_line.price_unit * inv_line.quantity else 0 end) as value, sum( case when uom.category_id != puom.category_id then pt.weight_net * inv_line.quantity else case when uom.factor_inv_data > 0 then pt.weight_net * inv_line.quantity * uom.factor_inv_data else pt.weight_net * inv_line.quantity / uom.factor end end ) as weight, sum( case when uom.category_id != puom.category_id then inv_line.quantity else case when uom.factor_inv_data > 0 then inv_line.quantity * uom.factor_inv_data else inv_line.quantity / uom.factor end end ) as supply_units,
if picking_id: wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
def action_ship_create(self, cr, uid, ids, *args): wf_service = netsvc.LocalService("workflow") picking_id = False move_obj = self.pool.get('stock.move') proc_obj = self.pool.get('procurement.order') company = self.pool.get('res.users').browse(cr, uid, uid).company_id for order in self.browse(cr, uid, ids, context={}): proc_ids = [] output_id = order.shop_id.warehouse_id.lot_output_id.id picking_id = False for line in order.order_line: proc_id = False date_planned = datetime.now() + relativedelta(days=line.delay or 0.0) date_planned = (date_planned - timedelta(days=company.security_lead)).strftime('%Y-%m-%d %H:%M:%S')
'account_id': a,
'account_id': account_id,
def action_invoice_create(self, cr, uid, ids, group=False, context=None): """ Creates invoice(s) for repair order. @param group: It is set to true when group invoice is to be generated. @return: Invoice Ids. """ res = {} invoices_group = {} inv_line_obj = self.pool.get('account.invoice.line') inv_obj = self.pool.get('account.invoice') repair_line_obj = self.pool.get('mrp.repair.line') repair_fee_obj = self.pool.get('mrp.repair.fee') for repair in self.browse(cr, uid, ids, context=context): res[repair.id] = False if repair.state in ('draft','cancel') or repair.invoice_id: continue if not (repair.partner_id.id and repair.partner_invoice_id.id): raise osv.except_osv(_('No partner !'),_('You have to select a Partner Invoice Address in the repair form !')) comment = repair.quotation_notes if (repair.invoice_method != 'none'): if group and repair.partner_invoice_id.id in invoices_group: inv_id = invoices_group[repair.partner_invoice_id.id] invoice = inv_obj.browse(cr, uid, inv_id) invoice_vals = { 'name': invoice.name +', '+repair.name, 'origin': invoice.origin+', '+repair.name, 'comment':(comment and (invoice.comment and invoice.comment+"\n"+comment or comment)) or (invoice.comment and invoice.comment or ''), } inv_obj.write(cr, uid, [inv_id], invoice_vals, context=context) else: if not repair.partner_id.property_account_receivable: raise osv.except_osv(_('Error !'), _('No account defined for partner "%s".') % repair.partner_id.name ) account_id = repair.partner_id.property_account_receivable.id inv = { 'name': repair.name, 'origin':repair.name, 'type': 'out_invoice', 'account_id': account_id, 'partner_id': repair.partner_id.id, 'address_invoice_id': repair.address_id.id, 'currency_id': repair.pricelist_id.currency_id.id, 'comment': repair.quotation_notes, 'fiscal_position': repair.partner_id.property_account_position.id } inv_id = inv_obj.create(cr, uid, inv) invoices_group[repair.partner_invoice_id.id] = inv_id self.write(cr, uid, repair.id, {'invoiced': True, 'invoice_id': inv_id})
sid = inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': inv.period_id.fiscalyear_id.id})
sequence_id = inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sequence_id, 'id', context=tmp_context)
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),)) inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: tmp_context = { 'fiscalyear_id': inv.period_id.fiscalyear_id.id } if inv.journal_id.invoice_sequence_id: sid = inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': inv.period_id.fiscalyear_id.id}) else: number = obj_seq.get_id(cr, uid, 'account.invoice.%s' % invtype, 'code=%s', context=tmp_context) 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
number = obj_seq.get_id(cr, uid, 'account.invoice.%s' % invtype, 'code=%s', context=tmp_context)
number = self.pool.get('ir.sequence').get_id(cr, uid, 'account.invoice.%s' % invtype, 'code', context=tmp_context)
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),)) inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: tmp_context = { 'fiscalyear_id': inv.period_id.fiscalyear_id.id } if inv.journal_id.invoice_sequence_id: sid = inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': inv.period_id.fiscalyear_id.id}) else: number = obj_seq.get_id(cr, uid, 'account.invoice.%s' % invtype, 'code=%s', context=tmp_context) 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
new_picking=picking_obj.copy(cr, uid, order_id.last_out_picking.id, {'name':'%s (return)' % order_id.name, 'move_lines':[], 'state':'draft', 'type':'in', 'type':'in', 'date':date_cur, }) new_order=order_obj.copy(cr,uid,order_id.id, {'name': 'Refund %s'%order_id.name, 'lines':[], 'statement_ids':[], 'last_out_picking':[]}) for line in order_id.lines: for r in data['form'].get('returns',[]): if line.id==r and (data['form']['return%s' %r]!=0.0): new_move=stock_move_obj.create(cr, uid,{ 'product_qty': data['form']['return%s' %r], 'product_uos_qty': uom_obj._compute_qty(cr, uid,data['form']['return%s' %r] ,line.product_id.uom_id.id), 'picking_id':new_picking, 'product_uom':line.product_id.uom_id.id, 'location_id':location_id, 'product_id':line.product_id.id, 'location_dest_id':stock_dest_id, 'name':'%s (return)' %order_id.name, 'date':date_cur, 'date_planned':date_cur,}) line_obj.copy(cr,uid,line.id,{'qty':-data['form']['return%s' %r], 'order_id': new_order, }) order_obj.write(cr,uid, new_order, {'state':'done'}) wf_service.trg_validate(uid, 'stock.picking',new_picking,'button_confirm', cr) picking_obj.force_assign(cr, uid, [new_picking], context) act = { 'domain': "[('id', 'in', ["+str(new_order)+"])]", 'name': 'Refunded Orders', 'view_type': 'form', 'view_mode': 'form,tree', 'res_model': 'pos.order', 'auto_refresh':0, 'res_id':new_order, 'view_id': False, 'type': 'ir.actions.act_window' }
if order_id.last_out_picking.id: new_picking=picking_obj.copy(cr, uid, order_id.last_out_picking.id, {'name':'%s (return)' % order_id.name, 'move_lines':[], 'state':'draft', 'type':'in', 'type':'in', 'date':date_cur, }) new_order=order_obj.copy(cr,uid,order_id.id, {'name': 'Refund %s'%order_id.name, 'lines':[], 'statement_ids':[], 'last_out_picking':[]}) for line in order_id.lines: for r in data['form'].get('returns',[]): if line.id==r and (data['form']['return%s' %r]!=0.0): new_move=stock_move_obj.create(cr, uid,{ 'product_qty': data['form']['return%s' %r], 'product_uos_qty': uom_obj._compute_qty(cr, uid,data['form']['return%s' %r] ,line.product_id.uom_id.id), 'picking_id':new_picking, 'product_uom':line.product_id.uom_id.id, 'location_id':location_id, 'product_id':line.product_id.id, 'location_dest_id':stock_dest_id, 'name':'%s (return)' %order_id.name, 'date':date_cur, 'date_planned':date_cur,}) line_obj.copy(cr,uid,line.id,{'qty':-data['form']['return%s' %r], 'order_id': new_order, }) order_obj.write(cr,uid, new_order, {'state':'done'}) wf_service.trg_validate(uid, 'stock.picking',new_picking,'button_confirm', cr) picking_obj.force_assign(cr, uid, [new_picking], context) act = { 'domain': "[('id', 'in', ["+str(new_order)+"])]", 'name': 'Refunded Orders', 'view_type': 'form', 'view_mode': 'form,tree', 'res_model': 'pos.order', 'auto_refresh':0, 'res_id':new_order, 'view_id': False, 'type': 'ir.actions.act_window' } else: raise wizard.except_wizard(_('Error'), _('Last out picking No find!'))
def _create_returns2(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) order_obj = pool.get('pos.order') line_obj = pool.get('pos.order.line') picking_obj = pool.get('stock.picking') stock_move_obj = pool.get('stock.move') picking_ids = picking_obj.search(cr, uid, [('pos_order', 'in', data['ids']), ('state', '=', 'done')]) clone_list = [] date_cur=time.strftime('%Y-%m-%d') uom_obj = pool.get('product.uom') wf_service = netsvc.LocalService("workflow") for order_id in order_obj.browse(cr, uid, data['ids'], context=context): prop_ids = pool.get("ir.property").search(cr, uid,[('name', '=', 'property_stock_customer')]) val = pool.get("ir.property").browse(cr, uid,prop_ids[0]).value cr.execute("select s.id from stock_location s, stock_warehouse w where w.lot_stock_id=s.id and w.id= %d "%(order_id.shop_id.warehouse_id.id)) res=cr.fetchone() location_id=res and res[0] or None stock_dest_id = int(val.split(',')[1]) new_picking=picking_obj.copy(cr, uid, order_id.last_out_picking.id, {'name':'%s (return)' % order_id.name, 'move_lines':[], 'state':'draft', 'type':'in', 'type':'in', 'date':date_cur, }) new_order=order_obj.copy(cr,uid,order_id.id, {'name': 'Refund %s'%order_id.name, 'lines':[], 'statement_ids':[], 'last_out_picking':[]}) for line in order_id.lines: for r in data['form'].get('returns',[]): if line.id==r and (data['form']['return%s' %r]!=0.0): new_move=stock_move_obj.create(cr, uid,{ 'product_qty': data['form']['return%s' %r], 'product_uos_qty': uom_obj._compute_qty(cr, uid,data['form']['return%s' %r] ,line.product_id.uom_id.id), 'picking_id':new_picking, 'product_uom':line.product_id.uom_id.id, 'location_id':location_id, 'product_id':line.product_id.id, 'location_dest_id':stock_dest_id, 'name':'%s (return)' %order_id.name, 'date':date_cur, 'date_planned':date_cur,}) line_obj.copy(cr,uid,line.id,{'qty':-data['form']['return%s' %r], 'order_id': new_order, }) order_obj.write(cr,uid, new_order, {'state':'done'}) wf_service.trg_validate(uid, 'stock.picking',new_picking,'button_confirm', cr) picking_obj.force_assign(cr, uid, [new_picking], context) act = { 'domain': "[('id', 'in', ["+str(new_order)+"])]", 'name': 'Refunded Orders', 'view_type': 'form', 'view_mode': 'form,tree', 'res_model': 'pos.order', 'auto_refresh':0, 'res_id':new_order, 'view_id': False, 'type': 'ir.actions.act_window' } return act
'amount': fields.float('Amount', required=True, digits_compute=dp.get_precision('Account'), help="For taxes of type percentage, enter % ratio between 0-1."),
'amount': fields.float('Amount', required=True, digits_compute=get_precision_tax(), help="For taxes of type percentage, enter % ratio between 0-1."),
def copy(self, cr, uid, id, default=None, context=None): if default is None: default = {} default = default.copy() default.update({'line_ids': []}) return super(account_tax_code, self).copy(cr, uid, id, default, context)
totalin = totalex = round(price_unit * quantity, precision)
def compute_all(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): """ RETURN: { 'total': 0.0, # Total without taxes 'total_included: 0.0, # Total with taxes 'taxes': [] # List of taxes, see compute for the format } """ precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account') totalin = totalex = round(price_unit * quantity, precision) totalex = totalex = round(price_unit * quantity, precision) tin = [] tex = [] for tax in taxes: if tax.price_include: tin.append(tax) else: tex.append(tax) tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner) tex = self._compute(cr, uid, tex, price_unit, quantity, address_id=address_id, product=product, partner=partner) for r in tin: totalex -= r['amount'] for r in tex: totalin += r['amount'] return { 'total': totalex, 'total_included': totalin, 'taxes': tin + tex }
tex = self._compute(cr, uid, tex, price_unit, quantity, address_id=address_id, product=product, partner=partner)
def compute_all(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): """ RETURN: { 'total': 0.0, # Total without taxes 'total_included: 0.0, # Total with taxes 'taxes': [] # List of taxes, see compute for the format } """ precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account') totalin = totalex = round(price_unit * quantity, precision) totalex = totalex = round(price_unit * quantity, precision) tin = [] tex = [] for tax in taxes: if tax.price_include: tin.append(tax) else: tex.append(tax) tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner) tex = self._compute(cr, uid, tex, price_unit, quantity, address_id=address_id, product=product, partner=partner) for r in tin: totalex -= r['amount'] for r in tex: totalin += r['amount'] return { 'total': totalex, 'total_included': totalin, 'taxes': tin + tex }
print "Deprecated, use compute_all(...)['taxes'] instead of compute(...) to manage prices with tax included"
logger = netsvc.Logger() logger.notifyChannel("warning", netsvc.LOG_WARNING, "Deprecated, use compute_all(...)['taxes'] instead of compute(...) to manage prices with tax included")
def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): print "Deprecated, use compute_all(...)['taxes'] instead of compute(...) to manage prices with tax included" return self._compute(cr, uid, taxes, price_unit, quantity, address_id, product, partner)
today = (last_month_date- 1).strftime('%Y-%m-%d')
today = (last_month_date- relativedelta(days=1)).strftime('%Y-%m-%d')
def init(self, cr, uid=1): """ This view will be used in dashboard The reason writing this code here is, we need to check date range from today to first date of fiscal year. """ pool_obj_fy = pooler.get_pool(cr.dbname).get('account.fiscalyear') today = time.strftime('%Y-%m-%d') fy_id = pool_obj_fy.find(cr, uid, exception=False) LIST_RANGES = [] if fy_id: fy_start_date = pool_obj_fy.read(cr, uid, fy_id, ['date_start'])['date_start'] fy_start_date = datetime.strptime(fy_start_date, '%Y-%m-%d') last_month_date = datetime.strptime(today, '%Y-%m-%d') - relativedelta(months=1)
<table width="100%"> <tr> <td width=60% style="padding-right:8px;"> <input id="sidebar_pad_datas" name="pad_name" size="5" /> </td> <td> <button>${_("Ok")}</button> </td> </tr> </table>
<input id="sidebar_pad_datas" name="pad_name" size="5" /> <button>${_("Ok")}</button>
def edit(self, template, template_text): output = super(SidebarTemplateEditor, self).edit(template, template_text)
'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True,),
def sign_out(self, cr, uid, ids, context=None): emp_obj = self.pool.get('hr.employee') if context is None: context = {} if not self.browse(cr, uid, ids, context=context)[0].date_current == time.strftime('%Y-%m-%d'): raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today')) emp_ids = emp_obj.search(cr, uid, [('user_id', '=', uid)]) context['sheet_id']=ids[0] emp_obj.attendance_action_change(cr, uid, emp_ids, type='sign_out', context=context,) return True
if il['analytics_id']:
if il.get('analytics_id', False):
def _get_analytic_lines(self, cr, uid, id): inv = self.browse(cr, uid, [id])[0] cur_obj = self.pool.get('res.currency')
repair_order = self.pool.get('mrp.repair').browse(cr, uid, record_id) if not repair_order.invoiced: res['arch'] = """ <form string="Cancel Repair" colspan="4"> <group col="2" colspan="2"> <label string="Do you want to continue?" colspan="4"/> <separator colspan="4"/> <button icon="gtk-cancel" special="cancel" string="No" readonly="0"/> <button name="cancel_repair" string="Yes" type="object" icon="gtk-ok"/> </group> </form> """
try: repair_order = self.pool.get('mrp.repair').browse(cr, uid, record_id) if not repair_order.invoiced: res['arch'] = """ <form string="Cancel Repair" colspan="4"> <group col="2" colspan="2"> <label string="Do you want to continue?" colspan="4"/> <separator colspan="4"/> <button icon="gtk-cancel" special="cancel" string="No" readonly="0"/> <button name="cancel_repair" string="Yes" type="object" icon="gtk-ok"/> </group> </form> """ except: return res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ Changes the view dynamically @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param context: A standard dictionary @return: New arch of view. """ record_id = context and context.get('active_id', False) or False res = super(repair_cancel, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False) if record_id: repair_order = self.pool.get('mrp.repair').browse(cr, uid, record_id) if not repair_order.invoiced: res['arch'] = """ <form string="Cancel Repair" colspan="4"> <group col="2" colspan="2"> <label string="Do you want to continue?" colspan="4"/> <separator colspan="4"/> <button icon="gtk-cancel" special="cancel" string="No" readonly="0"/> <button name="cancel_repair" string="Yes" type="object" icon="gtk-ok"/> </group> </form> """ return res
company_currency=False
company_currency = False tax_amount = self.read(cr, uid, ids[0], ['tax_amount'])['tax_amount'] tax_sign=1 if tax_amount < 0: tax_sign = -1 elif tax_amount == 0: tax_sign = 0
def amount_change(self, cr, uid, ids, amount, currency_id=False, company_id=False, date_invoice=False): cur_obj = self.pool.get('res.currency') company_obj = self.pool.get('res.company') company_currency=False if company_id: company_currency = company_obj.read(cr, uid, [company_id], ['currency_id'])[0]['currency_id'][0] if currency_id and company_currency: amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'tax_amount':amount}}
amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'tax_amount':amount}}
amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount*tax_sign, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'tax_amount': amount}}
def amount_change(self, cr, uid, ids, amount, currency_id=False, company_id=False, date_invoice=False): cur_obj = self.pool.get('res.currency') company_obj = self.pool.get('res.company') company_currency=False if company_id: company_currency = company_obj.read(cr, uid, [company_id], ['currency_id'])[0]['currency_id'][0] if currency_id and company_currency: amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'tax_amount':amount}}
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', c),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
def _get_account_line(self, cr, uid, ids, context={}): aac_ids = {} for acc in self.pool.get('account.analytic.account').browse(cr, uid, ids): aac_ids[acc.id] = True aal_ids = [] if aac_ids: aal_ids = self.pool.get('account.analytic.line').search(cr, uid, [('account_id','in',aac_ids.keys())], context=context) return aal_ids
print history_type
def _get_case_history(self, cr, uid, history_type, res_id, context=None): if not res_id: return
return False if type(self) != type(other):
def __eq__(self, other): if not self.context == other.context: return False if type(self) != type(other): return False # Two directory nodes, for the same document.directory, may have a # different context! (dynamic folders) if self.dctx != other.dctx: return False return self.dir_id == other.dir_id
return False if type(self) != type(other):
def __eq__(self, other): if not self.context == other.context: return False if type(self) != type(other): return False # Two nodes, for the same document.directory, may have a # different context! (dynamic folders) if self.dctx != other.dctx: return False return self.dir_id == other.dir_id
return False if type(self) != type(other):
def __eq__(self, other): if not self.context == other.context: return False if type(self) != type(other): return False if not self.res_model == other.res_model: return False if not self.res_id == other.res_id: return False if self.domain != other.domain: return False if self.dctx != other.dctx: return False return self.dir_id == other.dir_id
return False if type(self) != type(other):
def __eq__(self, other): if not self.context == other.context: return False if type(self) != type(other): return False if self.dctx != other.dctx: return False return self.file_id == other.file_id
entry_type = 'journal_pur_voucher' if invoice.type == 'in_refund': entry_type = 'cont_voucher'
def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''): if context is None: context = {} #TODO check if we can use different period for payment and the writeoff line assert len(ids)==1, "Can only pay one invoice at a time" invoice = self.browse(cr, uid, ids[0]) src_account_id = invoice.account_id.id # Take the seq as name for move types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} direction = types[invoice.type] #take the choosen date if 'date_p' in context and context['date_p']: date=context['date_p'] else: date=time.strftime('%Y-%m-%d')
entry_type = 'journal_sale_vou' if invoice.type == 'out_refund': entry_type = 'cont_voucher'
def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''): if context is None: context = {} #TODO check if we can use different period for payment and the writeoff line assert len(ids)==1, "Can only pay one invoice at a time" invoice = self.browse(cr, uid, ids[0]) src_account_id = invoice.account_id.id # Take the seq as name for move types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} direction = types[invoice.type] #take the choosen date if 'date_p' in context and context['date_p']: date=context['date_p'] else: date=time.strftime('%Y-%m-%d')
id = obj_action.create(cr, uid, val) self.write(cr, uid, [thisrule.id], {"state": "subscribed", "action_id": id})
action_id = obj_action.create(cr, uid, val) self.write(cr, uid, [thisrule.id], {"state": "subscribed", "action_id": action_id})
def subscribe(self, cr, uid, ids, *args): """ Subscribe Rule for auditing changes on object and apply shortcut for logs on that object. @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of Auddittrail Rule’s IDs. @return: True """ obj_action = self.pool.get('ir.actions.act_window') obj_model = self.pool.get('ir.model.data') #start Loop for thisrule in self.browse(cr, uid, ids): obj = self.pool.get(thisrule.object_id.model) if not obj: raise osv.except_osv( _('WARNING: audittrail is not part of the pool'), _('Change audittrail depends -- Setting rule as DRAFT')) self.write(cr, uid, [thisrule.id], {"state": "draft"}) val = { "name": 'View Log', "res_model": 'audittrail.log', "src_model": thisrule.object_id.model, "domain": "[('object_id','=', " + str(thisrule.object_id.id) + "), ('res_id', '=', active_id)]"
value = 'ir.actions.act_window,' + str(id)
value = 'ir.actions.act_window,' + str(action_id)
def subscribe(self, cr, uid, ids, *args): """ Subscribe Rule for auditing changes on object and apply shortcut for logs on that object. @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of Auddittrail Rule’s IDs. @return: True """ obj_action = self.pool.get('ir.actions.act_window') obj_model = self.pool.get('ir.model.data') #start Loop for thisrule in self.browse(cr, uid, ids): obj = self.pool.get(thisrule.object_id.model) if not obj: raise osv.except_osv( _('WARNING: audittrail is not part of the pool'), _('Change audittrail depends -- Setting rule as DRAFT')) self.write(cr, uid, [thisrule.id], {"state": "draft"}) val = { "name": 'View Log', "res_model": 'audittrail.log', "src_model": thisrule.object_id.model, "domain": "[('object_id','=', " + str(thisrule.object_id.id) + "), ('res_id', '=', active_id)]"
"name": fields.char("Name", size=32), "object_id": fields.many2one('ir.model', 'Object'), "user_id": fields.many2one('res.users', 'User'), "method": fields.selection((('read', 'Read'), ('write', 'Write'), ('unlink', 'Delete'), ('create', 'Create')), "Method"), "timestamp": fields.datetime("Date"), "res_id": fields.integer('Resource Id'), "line_ids": fields.one2many('audittrail.log.line', 'log_id', 'Log lines'),
"name": fields.char("Resource Name",size=64), "object_id": fields.many2one('ir.model', 'Object'), "user_id": fields.many2one('res.users', 'User'), "method": fields.char("Method", size=64), "timestamp": fields.datetime("Date"), "res_id": fields.integer('Resource Id'), "line_ids": fields.one2many('audittrail.log.line', 'log_id', 'Log lines'),
def unsubscribe(self, cr, uid, ids, *args): """ Unsubscribe Auditing Rule on object @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of Auddittrail Rule’s IDs. @return: True """ obj_action = self.pool.get('ir.actions.act_window') val_obj = self.pool.get('ir.values') #start Loop for thisrule in self.browse(cr, uid, ids): if thisrule.id in self.__functions: for function in self.__functions[thisrule.id]: setattr(function[0], function[1], function[2]) w_id = obj_action.search(cr, uid, [('name', '=', 'View Log'), ('res_model', '=', 'audittrail.log'), ('src_model', '=', thisrule.object_id.model)]) obj_action.unlink(cr, uid, w_id) value = "ir.actions.act_window" + ',' + str(w_id[0]) val_id = val_obj.search(cr, uid, [('model', '=', thisrule.object_id.model), ('value', '=', value)]) if val_id: res = ir.ir_del(cr, uid, val_id[0]) self.write(cr, uid, [thisrule.id], {"state": "draft"}) #End Loop return True
def get_value_text(self, cr, uid, field_name, values, object, context=None):
def get_value_text(self, cr, uid, field_name, values, model, context=None):
def unsubscribe(self, cr, uid, ids, *args): """ Unsubscribe Auditing Rule on object @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of Auddittrail Rule’s IDs. @return: True """ obj_action = self.pool.get('ir.actions.act_window') val_obj = self.pool.get('ir.values') #start Loop for thisrule in self.browse(cr, uid, ids): if thisrule.id in self.__functions: for function in self.__functions[thisrule.id]: setattr(function[0], function[1], function[2]) w_id = obj_action.search(cr, uid, [('name', '=', 'View Log'), ('res_model', '=', 'audittrail.log'), ('src_model', '=', thisrule.object_id.model)]) obj_action.unlink(cr, uid, w_id) value = "ir.actions.act_window" + ',' + str(w_id[0]) val_id = val_obj.search(cr, uid, [('model', '=', thisrule.object_id.model), ('value', '=', value)]) if val_id: res = ir.ir_del(cr, uid, val_id[0]) self.write(cr, uid, [thisrule.id], {"state": "draft"}) #End Loop return True
f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', field_name), ('model_id', '=', object.id)]) if f_id: field = pool.get('ir.model.fields').read(cr, uid, f_id)[0] model = field['relation'] if field['ttype'] == 'many2one': if values: if type(values) == tuple: values = values[0] val = pool.get(model).read(cr, uid, [values], [pool.get(model)._rec_name]) if val: return val[0][pool.get(model)._rec_name] elif field['ttype'] == 'many2many': value = [] if values: for id in values: val = pool.get(model).read(cr, uid, [id], [pool.get(model)._rec_name]) if val: value.append(val[0][pool.get(model)._rec_name]) return value elif field['ttype'] == 'one2many': if values: value = [] for id in values: val = pool.get(model).read(cr, uid, [id], [pool.get(model)._rec_name]) if val: value.append(val[0][pool.get(model)._rec_name]) return value return values def create_log_line(self, cr, uid, id, object, lines=[]):
field_pool = pool.get('ir.model.fields') model_pool = pool.get('ir.model') obj_pool = pool.get(model.model) if obj_pool._inherits: inherits_ids = model_pool.search(cr, uid, [('model', '=', obj_pool._inherits.keys()[0])]) field_ids = field_pool.search(cr, uid, [('name', '=', field_name), ('model_id', 'in', (model.id, inherits_ids[0]))]) else: field_ids = field_pool.search(cr, uid, [('name', '=', field_name), ('model_id', '=', model.id)]) field_id = field_ids and field_ids[0] or False assert field_id, _("'%s' field is not exits in '%s' model" %(field_name, model.model)) field = field_pool.read(cr, uid, field_id) relation_model = field['relation'] relation_model_pool = relation_model and pool.get(relation_model) or False if field['ttype'] == 'many2one': res = False relation_id = False if values and type(values) == tuple: relation_id = values[0] if relation_id and relation_model_pool: relation_model_object = relation_model_pool.read(cr, uid, relation_id, [relation_model_pool._rec_name]) res = relation_model_object[relation_model_pool._rec_name] return res elif field['ttype'] in ('many2many','one2many'): res = [] for relation_model_object in relation_model_pool.read(cr, uid, values, [relation_model_pool._rec_name]): res.append(relation_model_object[relation_model_pool._rec_name]) return res return values def create_log_line(self, cr, uid, log_id, model, lines=[]):
def get_value_text(self, cr, uid, field_name, values, object, context=None): """ Gets textual values for the fields e.g.: For field of type many2one it gives its name value instead of id
@param object: Object who's values are being changed
@param model: Object who's values are being changed
def create_log_line(self, cr, uid, id, object, lines=[]): """ Creates lines for changed fields with its old and new values
obj = pool.get(object.model)
obj_pool = pool.get(model.model) model_pool = pool.get('ir.model') field_pool = pool.get('ir.model.fields') log_line_pool = pool.get('audittrail.log.line')
def create_log_line(self, cr, uid, id, object, lines=[]): """ Creates lines for changed fields with its old and new values
if obj._inherits: inherits_ids = pool.get('ir.model').search(cr, uid, [('model', '=', obj._inherits.keys()[0])]) f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', line['name']), ('model_id', 'in', (object.id, inherits_ids[0]))])
if obj_pool._inherits: inherits_ids = model_pool.search(cr, uid, [('model', '=', obj_pool._inherits.keys()[0])]) field_ids = field_pool.search(cr, uid, [('name', '=', line['name']), ('model_id', 'in', (model.id, inherits_ids[0]))])
def create_log_line(self, cr, uid, id, object, lines=[]): """ Creates lines for changed fields with its old and new values
f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', line['name']), ('model_id', '=', object.id)]) if f_id: fields = pool.get('ir.model.fields').read(cr, uid, f_id) old_value = 'old_value' in line and line['old_value'] or '' new_value = 'new_value' in line and line['new_value'] or '' old_value_text = 'old_value_text' in line and line['old_value_text'] or '' new_value_text = 'new_value_text' in line and line['new_value_text'] or '' if old_value_text == new_value_text: continue if fields[0]['ttype'] == 'many2one': if type(old_value) == tuple: old_value = old_value[0] if type(new_value) == tuple: new_value = new_value[0] vals = { "log_id": id, "field_id": f_id[0], "old_value": old_value, "new_value": new_value, "old_value_text": old_value_text, "new_value_text": new_value_text, "field_description": fields[0]['field_description'] } line_id = pool.get('audittrail.log.line').create(cr, uid, vals) cr.commit()
field_ids = field_pool.search(cr, uid, [('name', '=', line['name']), ('model_id', '=', model.id)]) field_id = field_ids and field_ids[0] or False assert field_id, _("'%s' field is not exits in '%s' model" %(line['name'], model.model)) field = field_pool.read(cr, uid, field_id) old_value = 'old_value' in line and line['old_value'] or '' new_value = 'new_value' in line and line['new_value'] or '' old_value_text = 'old_value_text' in line and line['old_value_text'] or '' new_value_text = 'new_value_text' in line and line['new_value_text'] or '' if old_value_text == new_value_text: continue if field['ttype'] == 'many2one': if type(old_value) == tuple: old_value = old_value[0] if type(new_value) == tuple: new_value = new_value[0] vals = { "log_id": log_id, "field_id": field_id, "old_value": old_value, "new_value": new_value, "old_value_text": old_value_text, "new_value_text": new_value_text, "field_description": field['field_description'] } line_id = log_line_pool.create(cr, uid, vals)
def create_log_line(self, cr, uid, id, object, lines=[]): """ Creates lines for changed fields with its old and new values
def log_fct(self, db, uid, object, method, fct_src, *args):
def log_fct(self, db, uid, model, method, fct_src, *args):
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
@return: Returns result as per method of Object proxy """ logged_uids = []
@return: Returns result as per method of Object proxy """ res2 = args
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0]
resource_pool = pool.get(model) log_pool = pool.get('audittrail.log') model_pool = pool.get('ir.model') model_ids = model_pool.search(cr, uid, [('model', '=', model)]) model_id = model_ids and model_ids[0] or False assert model_id, _("'%s' Model is not exits..." %(model)) model = model_pool.browse(cr, uid, model_id)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
res_id = fct_src(db, uid, object, method, *args)
res_id = fct_src(db, uid, model.model, method, *args)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines)
resource = resource_pool.read(cr, uid, res_id, args[0].keys()) vals = { "method": method, "object_id": model.id, "user_id": uid, "res_id": resource['id'], } if 'id' in resource: del resource['id'] log_id = log_pool.create(cr, uid, vals) lines = [] for field in resource: line = { 'name': field, 'new_value': resource[field], 'new_value_text': self.get_value_text(cr, uid, field, resource[field], model) } lines.append(line) self.create_log_line(cr, uid, log_id, model, lines)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
if method in ('write'): res_ids = args[0] for res_id in res_ids: old_values = pool.get(model_object.model).read(cr, uid, res_id, args[1].keys()) old_values_text = {} for field in args[1].keys(): old_values_text[field] = self.get_value_text(cr, uid, field, old_values[field], model_object) res = fct_src(db, uid, object, method, *args) cr.commit() if res: new_values = pool.get(model_object.model).read(cr, uid, res_ids, args[1].keys())[0] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name}) lines = [] for field in args[1].keys(): if args[1].keys(): line = { 'name': field, 'new_value': field in new_values and new_values[field] or '', 'old_value': field in old_values and old_values[field] or '', 'new_value_text': self.get_value_text(cr, uid, field, new_values[field], model_object), 'old_value_text': old_values_text[field] } lines.append(line) cr.commit() self.create_log_line(cr, uid, id, model_object, lines) cr.close() return res if method in ('read'):
elif method in ('read'):
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
res = fct_src(db, uid, object, method, *args)
res = fct_src(db, uid, model.model, method, *args)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name}) lines = [] for field in old_values[res_id]: if old_values[res_id][field]: line = { 'name': field, 'old_value': old_values[res_id][field], 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model_object) } lines.append(line) cr.commit() self.create_log_line(cr, uid, id, model_object, lines)
vals = { "method": method, "object_id": model.id, "user_id": uid, "res_id": res_id, } log_id = log_pool.create(cr, uid, vals) lines = [] for field in old_values[res_id]: line = { 'name': field, 'old_value': old_values[res_id][field], 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model) } lines.append(line) self.create_log_line(cr, uid, log_id, model, lines)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
if method in ('unlink'):
elif method in ('unlink'):
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
old_values[res_id] = pool.get(model_object.model).read(cr, uid, res_id, [])
old_values[res_id] = resource_pool.read(cr, uid, res_id)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name})
vals = { "method": method, "object_id": model.id, "user_id": uid, "res_id": res_id, } log_id = log_pool.create(cr, uid, vals) lines = [] for field in old_values[res_id]: if field in ('id'): continue line = { 'name': field, 'old_value': old_values[res_id][field], 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model) } lines.append(line) self.create_log_line(cr, uid, log_id, model, lines) res = fct_src(db, uid, model.model, method, *args) cr.commit() cr.close() return res else: res_ids = args[0] old_values = {} fields = [] if len(args)>1 and type(args[1]) == dict: fields = args[1].keys() if type(res_ids) in (long, int): res_ids = [res_ids] if res_ids: for resource in resource_pool.read(cr, uid, res_ids): resource_id = resource['id'] if 'id' in resource: del resource['id'] old_values_text = {} old_value = {} for field in resource.keys(): old_value[field] = resource[field] old_values_text[field] = self.get_value_text(cr, uid, field, resource[field], model) old_values[resource_id] = {'text':old_values_text, 'value': old_value} res = fct_src(db, uid, model.model, method, *args) cr.commit() if res_ids: for resource in resource_pool.read(cr, uid, res_ids): resource_id = resource['id'] if 'id' in resource: del resource['id'] vals = { "method": method, "object_id": model.id, "user_id": uid, "res_id": resource_id, } log_id = log_pool.create(cr, uid, vals)
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id
for field in old_values[res_id]: if old_values[res_id][field]: line = { 'name': field, 'old_value': old_values[res_id][field], 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model_object) } lines.append(line) cr.commit() self.create_log_line(cr, uid, id, model_object, lines) res = fct_src(db, uid, object, method, *args)
for field in resource.keys(): line = { 'name': field, 'new_value': resource[field], 'old_value': old_values[resource_id]['value'][field], 'new_value_text': self.get_value_text(cr, uid, field, resource[field], model), 'old_value_text': old_values[resource_id]['text'][field] } lines.append(line) self.create_log_line(cr, uid, log_id, model, lines) cr.commit()
def log_fct(self, db, uid, object, method, fct_src, *args): """ Logging function: This function is performs logging oprations according to method @param db: the current database @param uid: the current user’s ID for security checks, @param object: Object who's values are being changed @param method: method to log: create, read, write, unlink @param fct_src: execute method of Object proxy @return: Returns result as per method of Object proxy """ logged_uids = [] pool = pooler.get_pool(db) cr = pooler.get_db(db).cursor() obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)]) model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0] if method in ('create'): res_id = fct_src(db, uid, object, method, *args) cr.commit() new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0] if 'id' in new_value: del new_value['id'] if not logged_uids or uid in logged_uids: resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id]) resource_name = resource_name and resource_name[0][1] or '' vals = { "method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name } id = pool.get('audittrail.log').create(cr, uid, vals) lines = [] for field in new_value: if new_value[field]: line = { 'name': field, 'new_value': new_value[field], 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object) } lines.append(line) self.create_log_line(cr, uid, id, model_object, lines) cr.commit() cr.close() return res_id