def _amount_all(self, cr, uid, ids, field_name, arg, context=None): """ Functional field function to calculate the amount_total,amount_untaxed, amount_tax and written_total of purchase order to add exstra amount to the purchase order. @return: Dictionary of fields value """ res = super(purchase, self)._amount_all(cr, uid, ids, field_name, arg, context) for order in self.browse(cr, uid, ids, context=context): freight_all = 0.0 packing_all = 0.0 for line in order.order_line: freight_all += line.price_unit_freight * line.product_qty packing_all += line.price_unit_packing * line.product_qty self.write(cr, uid, order.id, { 'freight': (freight_all), 'packing': (packing_all) }) res[order.id]['amount_total'] = res[ order.id]['amount_untaxed'] + res[order.id]['amount_tax'] + ( freight_all) + (packing_all) currency_format = order.company_id.currency_format total = res[order.id]['amount_total'] if currency_format == 'ar': res[order.id]['written_total'] = amount_to_text_ar( total, currency_format, order.currency_id['units_name'], order.currency_id['cents_name']) else: res[order.id]['written_total'] = amount_to_text_ar(total) return res
def convert(self, amount, currency_id): amount_in_word = '' currency_format = self.pool.get('res.users').browse(self.cr, self.uid, self.uid).company_id.currency_format if currency_format=='ar': if currency_id: currency = self.pool.get('res.currency').read(self.cr, self.uid, currency_id, ['units_name','cents_name'], context=self.context) amount_in_word = amount_to_text_ar(amount, currency_format, currency['units_name'], currency['cents_name']) else: amount_in_word = amount_to_text_ar(amount, currency_format) else: amount_in_word = amount_to_text(amount) return amount_in_word
def new_check(self, cr, uid, ids, context=None): """ This Method create new voucher when printing check from journal entry. @return: int ID of created voucher """ voucher_pool = self.pool.get('account.voucher') move = self.pool.get('account.move').browse(cr, uid, context.get('active_id',[]), context=context) cr.execute("SELECT COALESCE(sum(credit),0) amount,ml.partner_id,COALESCE(date_maturity,%s) date_maturity,ml.id id " \ "FROM account_move_line ml INNER JOIN account_move m ON m.id = ml.move_id " \ "INNER JOIN account_account acc ON acc.id = ml.account_id INNER JOIN account_account_type acc_type ON acc_type.id = user_type " \ "WHERE m.id = %s AND ml.credit > 0 AND type = 'liquidity' GROUP BY ml.partner_id,date_maturity,ml.id",(move.date,str(move.id),)) suppliers = cr.dictfetchall() for supplier in suppliers: voucher = { 'account_id':move.journal_id.default_credit_account_id.id, 'company_id':move.company_id.id, 'period_id':move.period_id.id, 'date':move.date, 'amount':supplier['amount'], 'journal_id':move.journal_id.id, 'pay_journal_id':move.journal_id.id, 'move_id':int(move.id), 'ref': move.name, 'partner_id':supplier['partner_id'], 'amount_in_word':amount_to_text_ar(supplier['amount'], 'ar'), 'type':'payment', 'allow_check':1, 'chk_status':True, 'date_due':supplier['date_maturity'] } voucher_id = voucher_pool.create(cr, uid, voucher, context=context) voucher_pool.write(cr, uid, voucher_id, {'state': 'posted'}, context=context) return voucher_id
def check_payment(self, cr, uid, ids, context=None): """ This method for creating new Check Payment or update the Check No. @return: dictionary, an action to close wizard """ data = self.browse(cr, uid, ids, context=context)[0] check_log_pool = self.pool.get('check.log') sequence_pool = self.pool.get('ir.sequence') move_pool = self.pool.get('account.move') voucher_pool = self.pool.get('account.voucher') move_line_pool = self.pool.get('account.move.line') voucher_id = (data.payment_id and data.payment_id.id) or (context['active_model'] == 'account.move' and self.check_move_data(cr, uid, ids, context=context)) if not data.payment_id: data.write({'payment_id':voucher_id}) if data.new_no: voucher = voucher_pool.browse(cr, uid, voucher_id, context=context) journal_id=voucher and (voucher.pay_journal_id or voucher.journal_id) if self._check_journal_seq(journal_id, context=context): chk_log_ids = check_log_pool.search(cr,uid,[('name','=',voucher.id),('status','=','active')], context=context) if data.state == 'reprint': check_log_pool.write(cr,uid,chk_log_ids, {'status': data.status}, context=context) sequence_pool.write(cr, uid, [journal_id.check_sequence.id], {'number_next_actual':data.new_no}, context=context) next_seq = sequence_pool.get_id(cr, uid, journal_id.check_sequence.id, context=context) voucher_pool.write(cr, uid,[voucher.id],{'amount_in_word': amount_to_text_ar(voucher.amount, 'ar'),'chk_seq': next_seq, 'chk_status':True, 'date_due': (voucher.date_due or voucher.date)}, context=context) if data.state == 'update': check_log_pool.write(cr,uid,chk_log_ids, {'check_no': next_seq}, context=context) else: check_log_pool.create(cr, uid,{'name': voucher.id, 'status': 'active', 'check_no': next_seq, 'journal_id':journal_id.id}, context=context) move_pool.write(cr, uid,[voucher.move_id.id], {'ref' : next_seq or ' '}, context=context) lines = move_line_pool.search(cr, uid,[('move_id','=',voucher.move_id.id)], context=context) move_line_pool.write(cr, uid,lines, {'ref' : next_seq or ' '}, context=context) if data.state != 'update': return self.print_report(cr, uid, ids, context=context) return {'type':'ir.actions.act_window_close'}
def onchange_price(self, cr, uid, ids, line_ids, tax_id, partner_id=False, context=None): """ Inherit method to update the text value of the check amount in the field amount_in_word based on the language format of the currency. @return: dictionary of values of fields to be updated """ res = super(account_voucher, self).onchange_price(cr, uid, ids, line_ids, tax_id, partner_id=partner_id, context=context) amount = res.get('value', {}).get('amount', 0) currency_format = self.pool.get('res.users').browse( cr, uid, uid).company_id.currency_format if currency_format == 'ar': currency_id = ids and self.browse( cr, uid, ids, context=context)[0].currency_id.id if currency_id: currency = self.pool.get('res.currency').read( cr, uid, currency_id, ['units_name', 'cents_name'], context=context) amount_in_word = amount_to_text_ar( amount, currency_format, currency.get('units_name', ''), currency.get('cents_name', '')) else: amount_in_word = amount_to_text_ar(amount, currency_format) else: amount_in_word = amount_to_text(amount) res.get('value', {}).update({'amount_in_word': amount_in_word}) return res
def _amount_to_word(self, cr, uid, ids, context=None): voucher_obj = self.pool.get('account.voucher') voucher_id = self._get_voucher_ids(cr, uid, context) if voucher_id: voucher = voucher_obj.browse(cr, uid, voucher_id, context) currency_format = 'ar' currency_id = voucher.currency_id and voucher.currency_id.id if currency_id: currency = self.pool.get('res.currency').read( cr, uid, currency_id, ['units_name', 'cents_name'], context=context) amount_in_word = amount_to_text_ar( voucher.amount, currency_format, currency.get('units_name', ''), currency.get('cents_name', '')) else: amount_in_word = amount_to_text_ar(voucher.amount, currency_format) voucher_obj.write(cr, uid, [voucher.id], {'amount_in_word': amount_in_word}) return True
def onchange_amount(self, cr, uid, ids, amount, context={}): """ On change function of amount to update amount in word. @return: Dictionary of amount and amount in word """ company = self.pool.get('res.users').browse(cr, uid, uid).company_id currency_format = company.currency_format amount_in_word = '' if currency_format=='ar': currency = self.pool.get('res.currency').read(cr, uid, company.currency_id.id, ['units_name','cents_name'], context=context) amount_in_word = amount_to_text_ar(amount, currency_format, currency['units_name'], currency['cents_name']) else: amount_in_word = amount_to_text(amount) return {'value': {'amount':amount,'amount_in_word': amount_in_word}}
def write(self, cr, uid, ids,vals, context=None): """ Override to force amount in word update @return: True """ super(purchase_letter_of_credit, self).write(cr, uid, ids, vals, context) amount = vals.get('amount',False) company = self.pool.get('res.users').browse(cr, uid, uid).company_id currency_format = company.currency_format amount_in_word = '' if currency_format=='ar': currency = self.pool.get('res.currency').read(cr, uid, company.currency_id.id, ['units_name','cents_name'], context=context) amount_in_word = amount_to_text_ar(amount, currency_format, currency['units_name'], currency['cents_name']) else: amount_in_word = amount_to_text(amount) vals.update({'amount':amount,'amount_in_word': amount_in_word}) return True
def onchange_partner_id_ratification(self, cr, uid, ids, partner_id, journal_id, ttype, price, context={}): """ This metthod call when changing Ratification amount or partner. @param int partner_id: Ratification record Partner, @param int journal_id: Ratification record Journal, @param char ttype: Ratification record type, @param float price: Ratification record amount, @return: dictionary conatins amount_in_word value """ ratification_journal = self.pool.get('res.company').browse( cr, uid, uid, context=context).ratification_journal_id default = {'value': {}} context.update({'type': 'purchase'}) default['value'][ 'journal_id'] = ratification_journal.id and ratification_journal.id or self._get_journal( cr, uid, context=context) if partner_id and ttype == 'ratification': default['value']['account_id'] = self.pool.get( 'res.partner').browse( cr, uid, partner_id, context=context).property_account_payable.id amount = 'amount' in default['value'] and default['value'][ 'amount'] or price currency_format = self.pool.get('res.users').browse( cr, uid, uid, context=context).company_id.currency_format amount_in_word = currency_format == 'ar' and amount_to_text_ar( amount, currency_format) or amount_to_text(amount) default['value'].update({'amount_in_word': amount_in_word}) if journal_id: #TODO: allow_check_writing = self.pool.get('account.journal').browse( cr, uid, journal_id, context=context).allow_check_writing default['value'].update({'allow_check': allow_check_writing}) return default
def create(self, cr, user, vals, context=None): """ Override to edit the name field by a new sequence and recalculate the amount_in_word value. @return: new object id """ created_id = super(purchase_letter_of_credit, self).create(cr, user, vals) amount = vals.get('amount',False) if ('name' not in vals) or (vals.get('name')=='/'): vals['name'] = self.pool.get('ir.sequence').get(cr, user, 'purchase.letter.of.credit') company = self.pool.get('res.users').browse(cr, user, user).company_id currency_format = company.currency_format amount_in_word = '' if currency_format=='ar': currency = self.pool.get('res.currency').read(cr, user, company.currency_id.id, ['units_name','cents_name'], context=context) amount_in_word = amount_to_text_ar(amount, currency_format, currency['units_name'], currency['cents_name']) else: amount_in_word = amount_to_text(amount) vals.update({'amount':amount,'amount_in_word': amount_in_word}) self.write(cr, user, created_id, vals, context) return created_id
def write(self, cr, uid, ids, vals, context=None): company = self.pool.get('res.users').browse(cr, uid, uid).company_id currency_format = company.currency_format amount_in_word = '' try: voucher = self.pool.get('account.voucher').browse(cr, uid, ids)[0] except: voucher = self.pool.get('account.voucher').browse(cr, uid, ids) if voucher: if currency_format == 'ar': currency = self.pool.get('res.currency').read( cr, uid, voucher.currency_id.id, ['units_name', 'cents_name'], context=context) amount_in_word = amount_to_text_ar(voucher.amount, currency_format, currency['units_name'], currency['cents_name']) else: amount_in_word = amount_to_text(amount) vals.update({'amount_in_word': amount_in_word}) return super(account_voucher, self).write(cr, uid, ids, vals, context)
def done(self, cr, uid,ids, context={}): """ Workflow function to change media service order state to done, check media service order accounts and create account voucher with meida service order total cost. @return: True """ account_journal_obj = self.pool.get('account.journal') account_obj = self.pool.get('account.account') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') affairs_account_obj = self.pool.get('admin_affairs.account') affairs_model_obj = self.pool.get('admin.affairs.model') if self.browse(cr,uid,ids[0],context).execution_type == 'internal': self.write(cr, uid, ids, {'purchase_state':'2bpurchased'},context=context) for record in self.browse(cr,uid,ids,context=context): if record.execution_type == 'external': if record.total_cost < 1 : raise osv.except_osv(_('Error'), _("Please enter the Right Cost ")) #Account Configuartion for all media order affairs_model_ids = affairs_model_obj.search(cr, uid, [('model','=','media.order')], context=context) affairs_account_ids = affairs_account_obj.search(cr, uid, [('model_id','=',affairs_model_ids[0])], context=context) if not affairs_account_ids: raise osv.except_osv(_('Error'), _("Please enter Media Order accounting configuration")) affairs_account = affairs_account_obj.browse(cr, uid, affairs_account_ids[0], context=context) accoun_model_ids = affairs_model_obj.search(cr, uid, [('model','=','media.order')], context=context) account_ids = account_obj.search(cr, uid, [('company_id','=',record.category_id.company_id.id),('code','=',str(affairs_account.code))], context=context) journal_ids = account_journal_obj.search(cr, uid, [('company_id','=',record.category_id.company_id.id),('name','=',affairs_account.name_type.name)], context=context) journal_id = journal_ids and journal_ids[0] or affairs_account.journal_id.id account_id = account_ids and account_ids[0] or affairs_account.account_id.id analytic_id = affairs_account.analytic_id #Define Department & company & analytic account for normal case dept = record.department_id.id analytic_account = record.category_id.analytic_id company = record.company_id.id #Account Configuartion per media order category category_accounts_ids = account_obj.search(cr, uid, [('company_id','=',record.category_id.company_id.id),('code','=',str(record.category_id.code))], context=context) if not category_accounts_ids : raise osv.except_osv(_('Error'), _("Please enter Media category accounting configuration")) cat_account_id = category_accounts_ids[0] if record.category_id.company_id.code == "HQ" and record.company_id.code != "HQ": print "True we here" dept = record.category_id.department_id.id analytic_account = record.category_id.department_id.analytic_account_id.id company = record.category_id.company_id.id # Creating Voucher voucher_id = voucher_obj.create(cr, uid, { 'amount': record.total_cost, 'type': 'ratification', 'date': time.strftime('%Y-%m-%d'), 'partner_id': record.partner_id.id, 'department_id': dept , 'state': 'draft', 'company_id' : company , 'journal_id':journal_id , 'narration': 'Media order no :'+record.name, 'amount_in_word':amount_to_text_ar(record.total_cost), }, context={}) voucher_number = voucher_obj.browse(cr,uid,voucher_id,context=context) #Creating voucher lines voucher_line_dict={ 'name': record.name, 'voucher_id':voucher_id, 'account_id':cat_account_id , 'account_analytic_id':analytic_account, 'amount':record.total_cost, 'type':'dr', } voucher_line=voucher_line_obj.create(cr,uid,voucher_line_dict) copy_attachments(self,cr,uid,[record.id],'media.order',voucher_id,'account.voucher', context) self.write(cr, uid, ids, {'voucher_no':voucher_number.number},context=context) self.changes_state(cr, uid, ids,{'state':'done'},context=context) return True
def done(self, cr, uid, ids, context=None): """ Workflow function changes order state to done, chech the total_cost and create account voucher with the cost. @return: Boolean True """ account_journal_obj = self.pool.get('account.journal') account_obj = self.pool.get('account.account') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') affairs_account_obj = self.pool.get('admin_affairs.account') affairs_model_obj = self.pool.get('admin.affairs.model') payment_enrich_obj = self.pool.get('payment.enrich') payment_enrich_lines_obj = self.pool.get('payment.enrich.lines') for record in self.browse(cr, uid, ids, context=context): if record.total_cost < 1: raise osv.except_osv(_('Error'), _("Please enter the Right Cost ")) # Creating enrich if record.payment_selection == 'enrich': details = smart_str('Public Relation Request No:' + record.name + '\nProcedure For:' + record.procedure_for + '\nprocedure:' + record.procedure_id.name + '\nPurpose:' + record.purpose.name) #details = 'Public Relation Request No:'+record.name enrich_payment_lines_id = payment_enrich_lines_obj.create( cr, uid, { 'enrich_id': record.enrich_category.id, 'cost': record.total_cost, 'date': time.strftime('%Y-%m-%d'), 'state': 'draft', 'name': details, 'department_id': record.department_id.id, }, context=context) self.write(cr, uid, ids, {'state': 'done'}, context=context) elif record.payment_selection == 'voucher': affairs_model_ids = affairs_model_obj.search( cr, uid, [('model', '=', 'foreigners.procedures.request')], context=context) affairs_account_ids = affairs_account_obj.search( cr, uid, [('model_id', '=', affairs_model_ids[0])], context=context) if not affairs_account_ids: raise osv.except_osv( _('Error'), _("Please enter the Foreigner/sudanese request accounting configuration" )) affairs_account = affairs_account_obj.browse( cr, uid, affairs_account_ids[0], context=context) accoun_model_ids = affairs_model_obj.search( cr, uid, [('model', '=', 'foreigners.procedures.request')], context=context) account_ids = account_obj.search( cr, uid, [('company_id', '=', record.company_id.id), ('code', '=', str(affairs_account.code))], context=context) journal_ids = account_journal_obj.search( cr, uid, [('company_id', '=', record.company_id.id), ('name', '=', affairs_account.name_type.name)], context=context) if journal_ids: journal_id = journal_ids[0] else: journal_id = affairs_account.journal_id.id if account_ids: account_id = account_ids[0] else: account_id = affairs_account.account_id.id analytic_id = affairs_account.analytic_id # Creating Voucher voucher_id = voucher_obj.create( cr, uid, { 'amount': record.total_cost, 'type': 'ratification', 'date': time.strftime('%Y-%m-%d'), 'partner_id': record.partner_id.id, 'department_id': record.department_id.id, 'state': 'draft', 'journal_id': journal_id, 'narration': 'Foreigner/sudanese Request no :' + record.name, 'amount_in_word': amount_to_text_ar(record.total_cost), }, context={}) #voucher_number = voucher_obj.browse(cr,uid,voucher_id,context=context) #Creating voucher lines voucher_line_dict = { 'name': record.name, 'voucher_id': voucher_id, 'account_id': account_id, 'account_analytic_id': analytic_id or record.department_id.analytic_account_id.id, 'amount': record.total_cost, 'type': 'dr', } voucher_line = voucher_line_obj.create(cr, uid, voucher_line_dict) #################### update workflow state############### voucher_state = 'draft' if record.company_id.affairs_voucher_state: voucher_state = record.company_id.affairs_voucher_state if voucher_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'account.voucher', voucher_id, voucher_state, cr) voucher_obj.write( cr, uid, voucher_id, { 'type': 'ratification', 'ratification': True, 'state': voucher_state }, context) copy_attachments(self, cr, uid, [record.id], 'foreigners.procedures.request', voucher_id, 'account.voucher', context) self.write(cr, uid, ids, { 'state': 'done', 'voucher_no': voucher_id }, context=context) return True
def _process(self,data , dep_ids = None, outsite_scale=False): allow_column_index = -1 #specify where to show allowance totals department_title = "" page_trans_totals = [] transfer_total_basics = [] transfer_totals= {#store total for printing in each page the summation of last pages records 'loan' : [] , 'allow':[] , 'deduct':[] , 'net' : [] , } in_salary_sheet = True ad_type = data['type'] #allowance or deduction #paysheet = data['pay_sheet'] list_to_str = lambda items : ",".join(str(i) for i in items) payroll_id = data.get('payroll_ids') payroll_ids_str =str(data['payroll_ids']) #ad_ids_condition = "" #if data['allow_deduct_ids']: # ad_ids_condition = " and public.hr_allowance_deduction_archive.allow_deduct_id in (%s)" %(list_to_str(data['allow_deduct_ids'])) ad_condition = "" ad_condition = "and public.hr_allowance_deduction.name_type = '%s' "%('allow') #step 1 : get all employee in passed month , later get ids of passed employees self.cr.execute( ''' SELECT distinct public.hr_salary_degree.id as degree_id , public.hr_salary_degree.name as degree_name, public.hr_salary_degree.sequence as degree_seq, public.hr_salary_degree.basis as basic_salary FROM hr_salary_degree WHERE hr_salary_degree.payroll_id = %s ; ''' %(payroll_ids_str) ) emp_res = self.cr.dictfetchall() #step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute( ''' SELECT public.hr_allowance_deduction.id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction WHERE public.hr_allowance_deduction.in_salary_sheet=%s %s order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ; ''' %(in_salary_sheet,ad_condition,)) allow_deduct_res = self.cr.dictfetchall() print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",allow_deduct_res #step 3 : get all allowaces/deductions for employees self.cr.execute( ''' SELECT hr_salary_allowance_deduction.id, hr_salary_allowance_deduction.allow_deduct_id , hr_salary_allowance_deduction.degree_id , hr_salary_allowance_deduction.amount FROM hr_salary_allowance_deduction WHERE hr_salary_allowance_deduction.payroll_id = %s ; ''' %(payroll_ids_str)) emp_allows_res = self.cr.dictfetchall() #step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in ['deduct'] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow' , 'deduct'] #step 4 : prepare table data emp_data = [] # array for store employees data allow_deduct_totals = [0 for i in range(len(allow_deduct_res))]#prepare array for store totals page_trans_totals = []#array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_allows = 0 total_deducts = 0 for j , emp in enumerate(emp_res) : #print "emp>>>>>>>>>>>>>>>>>",emp_res amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 for i , allow_deduct in enumerate(allow_deduct_res): #print "emp>>>>>>>>>>>>>>>>>",emp_res #print "alow>>",allow_deduct_res amount_obj = filter(lambda arch : arch['degree_id'] == emp['degree_id'] and arch['allow_deduct_id'] == allow_deduct['id'] , emp_allows_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow' : emp_total_allow += emp_amount else : emp_total_deduct += emp_amount allow_deduct_totals[i] = allow_deduct_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 total_allows += emp_total_allow total_deducts += emp_total_deduct emp_row = { 'emp_name' : emp['degree_name'] , 'emp_job' : ' ', 'emp_degree':' ', 'amounts' : [round(am , 2) for am in amounts] , 'basic_salary' : emp['basic_salary'] , 'emp_total_deduct' : round(emp_total_deduct,2), 'emp_total_allow' : round(emp_total_allow,2), 'emp_net' : round(emp_total_allow - emp_total_deduct , 2), } #here checking break point for register total amounts of processed records if (j+1) % BREAK_POINT == 0: page_trans_totals.append([round(adt , 2) for adt in allow_deduct_totals]) transfer_total_basics.append(round(total_basics , 2)) transfer_totals['allow'].append(round(total_allows,2)) transfer_totals['deduct'].append(round(total_deducts,2)) transfer_totals['net'].append(round(total_allows - total_deducts , 2)) emp_data.append(emp_row) total_nets = total_allows - total_deducts #step 5 : prepare allowances/deductions header header = [] #store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow' : allow_header.append(allow_deduct['name']) allow_column_index += 1 else : deduct_header.append(allow_deduct['name']) basic_len = len(filter(lambda ad : ad['name_type'] == 'allow' and ad['is_basic_salary_item'] , allow_deduct_res)) + 1 allow_len = len(filter(lambda ad : ad['name_type'] == 'allow' and not ad['is_basic_salary_item'] ,allow_deduct_res)) deduct_len = len(filter(lambda ad : ad['name_type'] == 'deduct' ,allow_deduct_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 additional_rows = 0 #else: # additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT) amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data' : emp_data , 'headrs' : header , 'allow_header' : allow_header , 'deduct_header' : deduct_header , 'allow_deduct_totals' : allow_deduct_totals , 'page_trans_totals' : page_trans_totals , 'BREAK_POINT' : BREAK_POINT , 'page_trans_totals' : lambda index : page_trans_totals[int(index/BREAK_POINT)] , 'include_bascic_salary' : include_bascic_salary , 'total_basics' : round(total_basics,2) , 'transfer_total_basics' : lambda index : transfer_total_basics[int(index/BREAK_POINT)] , 'len_emp_data' : len(emp_data) , 'transfer_total' : lambda key , index : transfer_totals[key][int(index/BREAK_POINT)] , 'include_allow_total' : include_allow_total , 'include_deduct_total' : include_deduct_total , 'include_net_total' : include_net_total , 'total_allows' : round(total_allows,2) , 'total_deducts' : round(total_deducts,2) , 'total_nets' : round(total_nets,2), 'department_title' : department_title , 'allow_column_index' : allow_column_index , 'basic_len' : basic_len , 'allow_len' : allow_len , 'deduct_len' : deduct_len , 'additional_rows' :additional_rows , 'amount_in_words' : amount_in_words , } return res
def _process(self, data, dep_ids=None, outsite_scale=False): allow_column_index = -1 # specify where to show allowance totals department_title = "" page_trans_totals = [] transfer_total_basics = [] transfer_totals = { # store total for printing in each page the summation of last pages records 'loan': [], 'allow': [], 'deduct': [], 'net': [], } res = [] emp_condition = "" year = data['year'] month = data['month'] in_salary_sheet = True ad_type = data['type'] # allowance or deduction # paysheet = data['pay_sheet'] # list_to_str = lambda items : ",".join(str(i) for i in items) company_id = data.get('company_id') # company_ids_str =list_to_str(company_id) ad_ids_condition = "" # if data['allow_deduct_ids']: # ad_ids_condition = " and public.hr_allowance_deduction_archive.allow_deduct_id in (%s)" %(list_to_str(data['allow_deduct_ids'])) ad_condition = "" # if ad_type : # ad_condition = "and public.hr_allowance_deduction.name_type = '%s' "%(ad_type) if data['type'] == 'company' and data['company_idss']: # step 1 : get all employee in passed month , later get ids of passed employees if len(data['company_idss']) > 1: self.cr.execute(''' SELECT hr_payroll_main_archive.company_id as company_id , public.res_company.name as company_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.res_company, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.company_id = res_company.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.company_id in %s group by hr_payroll_main_archive.company_id, res_company.name ''' % (month, year, in_salary_sheet, tuple(data['company_idss']))) comp_res = self.cr.dictfetchall() # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute(''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet, tuple(data['company_idss']))) allow_deduct_res = self.cr.dictfetchall() # step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.company_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in %s GROUP by hr_payroll_main_archive.company_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, tuple(data['company_idss']))) comp_allows_res = self.cr.dictfetchall() elif len(data['company_idss']) == 1: data['company_idss'] = data['company_idss'][0] self.cr.execute(''' SELECT hr_payroll_main_archive.company_id as company_id , public.res_company.name as company_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.res_company, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.company_id = res_company.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.company_id = %s group by hr_payroll_main_archive.company_id, res_company.name ''' % (month, year, in_salary_sheet, data['company_idss'])) comp_res = self.cr.dictfetchall() # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute(''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id = %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet, data['company_idss'])) allow_deduct_res = self.cr.dictfetchall() # step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.company_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id = %s GROUP by hr_payroll_main_archive.company_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, data['company_idss'])) comp_allows_res = self.cr.dictfetchall() # step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in [ 'deduct' ] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow', 'deduct'] # step 4 : prepare table data emp_data = [] # array for store employees data allow_deduct_totals = [0 for i in range(len(allow_deduct_res)) ] # prepare array for store totals page_trans_totals = [ ] # array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_comp_basic = 0 total_allows = 0 total_deducts = 0 # for j , emp in enumerate(emp_res) : for j, emp in enumerate(comp_res): amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 for i, allow_deduct in enumerate(allow_deduct_res): # amount_obj = filter(lambda arch : arch['employee_id'] == emp['emp_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'] , emp_allows_res) amount_obj = filter( lambda arch: arch['company_id'] == emp['company_id'] and arch['allow_deduct_id'] == allow_deduct[ 'allow_deduct_id'], comp_allows_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow': emp_total_allow += emp_amount else: emp_total_deduct += emp_amount allow_deduct_totals[ i] = allow_deduct_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] # emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 emp_total_allow += emp['basic_salary'] total_comp_basic += emp['basic_salary'] total_allows += emp_total_allow total_deducts += emp_total_deduct emp_row = { 'emp_name': emp['company_name'], # 'emp_job' : emp['emp_job'], # 'emp_degree':emp['emp_degree'], 'amounts': [round(am, 2) for am in amounts], 'basic_salary': emp['basic_salary'], 'emp_total_deduct': round(emp_total_deduct, 2), 'emp_total_allow': round(emp_total_allow, 2), 'emp_net': round(emp_total_allow - emp_total_deduct, 2), } # here checking break point for register total amounts of processed records if (j + 1) % BREAK_POINT == 0: page_trans_totals.append( [round(adt, 2) for adt in allow_deduct_totals]) transfer_total_basics.append(round(total_basics, 2)) transfer_totals['allow'].append(round(total_allows, 2)) transfer_totals['deduct'].append(round(total_deducts, 2)) transfer_totals['net'].append( round(total_allows - total_deducts, 2)) emp_data.append(emp_row) total_nets = total_allows - total_deducts # step 5 : prepare allowances/deductions header header = [] # store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow': allow_header.append(allow_deduct['name']) allow_column_index += 1 else: deduct_header.append(allow_deduct['name']) basic_len = len( filter( lambda ad: ad['name_type'] == 'allow' and ad[ 'is_basic_salary_item'], allow_deduct_res)) + 1 allow_len = len( filter( lambda ad: ad['name_type'] == 'allow' and not ad[ 'is_basic_salary_item'], allow_deduct_res)) deduct_len = len( filter(lambda ad: ad['name_type'] == 'deduct', allow_deduct_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 else: additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT) amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data': emp_data, 'headrs': header, 'allow_header': allow_header, 'deduct_header': deduct_header, 'allow_deduct_totals': allow_deduct_totals, 'page_trans_totals': page_trans_totals, 'BREAK_POINT': BREAK_POINT, 'page_trans_totals': lambda index: page_trans_totals[int(index / BREAK_POINT)], 'include_bascic_salary': include_bascic_salary, 'total_basics': round(total_basics, 2), 'transfer_total_basics': lambda index: transfer_total_basics[int(index / BREAK_POINT)], 'len_emp_data': len(emp_data), 'transfer_total': lambda key, index: transfer_totals[key][int(index / BREAK_POINT )], 'include_allow_total': include_allow_total, 'include_deduct_total': include_deduct_total, 'include_net_total': include_net_total, 'total_allows': round(total_allows, 2), 'total_deducts': round(total_deducts, 2), 'total_nets': round(total_nets, 2), 'department_title': department_title, 'allow_column_index': allow_column_index, 'basic_len': basic_len, 'allow_len': allow_len, 'deduct_len': deduct_len, 'additional_rows': additional_rows, 'amount_in_words': amount_in_words, } if (data['type'] == 'location' or data['type'] == 'department') and data['department_ids']: # step 1 : get all employee in passed month , later get ids of passed employees if len(data['department_ids']) > 1: self.cr.execute(''' SELECT hr_payroll_main_archive.department_id as department_id , public.hr_department.name as dep_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.hr_department, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.department_id = hr_department.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.department_id in %s group by hr_payroll_main_archive.department_id, hr_department.name ''' % (month, year, in_salary_sheet, tuple(data['department_ids']))) dep_res = self.cr.dictfetchall() # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute(''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet, tuple(data['department_ids']))) allow_deduct_res = self.cr.dictfetchall() # step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.department_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s GROUP by hr_payroll_main_archive.department_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, tuple(data['department_ids']))) dep_allows_res = self.cr.dictfetchall() if len(data['department_ids']) == 1: data['department_ids'] = data['department_ids'][0] self.cr.execute( ''' SELECT hr_payroll_main_archive.department_id as department_id , public.hr_department.name as dep_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.hr_department, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.department_id = hr_department.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.department_id = %s group by hr_payroll_main_archive.department_id, hr_department.name ''' % (month, year, in_salary_sheet, data['department_ids'])) dep_res = self.cr.dictfetchall() # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute( ''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id = %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet, data['department_ids'])) allow_deduct_res = self.cr.dictfetchall() # step 3 : get all allowaces/deductions for employees self.cr.execute( ''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.department_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id = %s GROUP by hr_payroll_main_archive.department_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, data['department_ids'])) dep_allows_res = self.cr.dictfetchall() # step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in [ 'deduct' ] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow', 'deduct'] # step 4 : prepare table data emp_data = [] # array for store employees data allow_deduct_totals = [0 for i in range(len(allow_deduct_res)) ] # prepare array for store totals page_trans_totals = [ ] # array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_allows = 0 total_deducts = 0 # for j , emp in enumerate(emp_res) : for j, emp in enumerate(dep_res): amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 for i, allow_deduct in enumerate(allow_deduct_res): # amount_obj = filter(lambda arch : arch['employee_id'] == emp['emp_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'] , emp_allows_res) amount_obj = filter( lambda arch: arch['department_id'] == emp[ 'department_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'], dep_allows_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow': emp_total_allow += emp_amount else: emp_total_deduct += emp_amount allow_deduct_totals[ i] = allow_deduct_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] # emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 emp_total_allow += emp['basic_salary'] total_allows += emp_total_allow total_deducts += emp_total_deduct emp_row = { 'emp_name': emp['dep_name'], # 'emp_job' : emp['emp_job'], # 'emp_degree':emp['emp_degree'], 'amounts': [round(am, 2) for am in amounts], 'basic_salary': emp['basic_salary'], 'emp_total_deduct': round(emp_total_deduct, 2), 'emp_total_allow': round(emp_total_allow, 2), 'emp_net': round(emp_total_allow - emp_total_deduct, 2), } # here checking break point for register total amounts of processed records if (j + 1) % BREAK_POINT == 0: page_trans_totals.append( [round(adt, 2) for adt in allow_deduct_totals]) transfer_total_basics.append(round(total_basics, 2)) transfer_totals['allow'].append(round(total_allows, 2)) transfer_totals['deduct'].append(round(total_deducts, 2)) transfer_totals['net'].append( round(total_allows - total_deducts, 2)) emp_data.append(emp_row) total_nets = total_allows - total_deducts # step 5 : prepare allowances/deductions header header = [] # store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow': allow_header.append(allow_deduct['name']) allow_column_index += 1 else: deduct_header.append(allow_deduct['name']) basic_len = len( filter( lambda ad: ad['name_type'] == 'allow' and ad[ 'is_basic_salary_item'], allow_deduct_res)) + 1 allow_len = len( filter( lambda ad: ad['name_type'] == 'allow' and not ad[ 'is_basic_salary_item'], allow_deduct_res)) deduct_len = len( filter(lambda ad: ad['name_type'] == 'deduct', allow_deduct_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 else: additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT) amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data': emp_data, 'headrs': header, 'allow_header': allow_header, 'deduct_header': deduct_header, 'allow_deduct_totals': allow_deduct_totals, 'page_trans_totals': page_trans_totals, 'BREAK_POINT': BREAK_POINT, 'page_trans_totals': lambda index: page_trans_totals[int(index / BREAK_POINT)], 'include_bascic_salary': include_bascic_salary, 'total_basics': round(total_basics, 2), 'transfer_total_basics': lambda index: transfer_total_basics[int(index / BREAK_POINT)], 'len_emp_data': len(emp_data), 'transfer_total': lambda key, index: transfer_totals[key][int(index / BREAK_POINT )], 'include_allow_total': include_allow_total, 'include_deduct_total': include_deduct_total, 'include_net_total': include_net_total, 'total_allows': round(total_allows, 2), 'total_deducts': round(total_deducts, 2), 'total_nets': round(total_nets, 2), 'department_title': department_title, 'allow_column_index': allow_column_index, 'basic_len': basic_len, 'allow_len': allow_len, 'deduct_len': deduct_len, 'additional_rows': additional_rows, 'amount_in_words': amount_in_words, } if data['type'] == 'state' and data['company_idss']: emp_data = [] # array for store employees data page_trans_totals = [ ] # array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_allows = 0 total_deducts = 0 all_child_ids = self.pool.get('res.company').search( self.cr, self.uid, [(('parent_id', '=', data['company_idss']))]) self.cr.execute(''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet, tuple(all_child_ids))) allow_deduct_res = self.cr.dictfetchall() allow_deduct_totals = [0 for i in range(len(allow_deduct_res)) ] # prepare array for store totals pr = 0 for comp_id in data['company_idss']: pr += 1 curr_com = self.pool.get('res.company').browse( self.cr, self.uid, comp_id).name # step 1 : get all employee in passed month , later get ids of passed employees # Get Child Company # make for to sum child company # define amount over for #print "parent>>>", data['company_idss'] child_ids = self.pool.get('res.company').search( self.cr, self.uid, [(('parent_id', '=', comp_id))]) #print "Child Comp>>>", child_ids if len(child_ids) > 1: self.cr.execute(''' SELECT hr_payroll_main_archive.company_id as company_id , public.res_company.name as company_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.res_company, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.company_id = res_company.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.company_id in %s group by hr_payroll_main_archive.company_id, res_company.name ''' % (month, year, in_salary_sheet, tuple(child_ids))) comp_res = self.cr.dictfetchall() # print "basic>>>", comp_res # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions # print "Allow_deduct>>", allow_deduct_res # step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.company_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in %s GROUP by hr_payroll_main_archive.company_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, tuple(child_ids))) comp_allows_res = self.cr.dictfetchall() # print "Comp Allow_ded>>", comp_allows_res elif len(child_ids) == 1: child_ids = child_ids[0] self.cr.execute(''' SELECT hr_payroll_main_archive.company_id as company_id , public.res_company.name as company_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.res_company, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.company_id = res_company.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.company_id = %s group by hr_payroll_main_archive.company_id, res_company.name ''' % (month, year, in_salary_sheet, child_ids)) comp_res = self.cr.dictfetchall() # print "basic>>>", comp_res # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions # print "Allow_deduct>>", allow_deduct_res # step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.company_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id = %s GROUP by hr_payroll_main_archive.company_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet, child_ids)) comp_allows_res = self.cr.dictfetchall() # step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in [ 'deduct' ] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow', 'deduct'] # step 4 : prepare table data # For All Company # for j , emp in enumerate(emp_res) : # Basic Salary>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 total_company_basic = 0 allow_deduct_com_totals = [ 0 for i in range(len(allow_deduct_res)) ] for j, emp in enumerate(comp_res): # Alow Ded Name=Header>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> for i, allow_deduct in enumerate(allow_deduct_res): # amount_obj = filter(lambda arch : arch['employee_id'] == emp['emp_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'] , emp_allows_res) amount_obj = filter( lambda arch: arch['company_id'] == emp[ 'company_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'], comp_allows_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow': emp_total_allow += emp_amount else: emp_total_deduct += emp_amount allow_deduct_totals[ i] = allow_deduct_totals[i] + emp_amount allow_deduct_com_totals[ i] = allow_deduct_com_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] total_company_basic += emp['basic_salary'] # emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 emp_total_allow += emp['basic_salary'] total_allows += emp_total_allow total_deducts += emp_total_deduct # create company Row emp_row = { 'emp_name': curr_com, # 'emp_job' : emp['emp_job'], # 'emp_degree':emp['emp_degree'], 'amounts': allow_deduct_com_totals, 'basic_salary': total_company_basic, 'emp_total_deduct': round(emp_total_deduct, 2), 'emp_total_allow': round(emp_total_allow, 2), 'emp_net': round(emp_total_allow - emp_total_deduct, 2), } # here checking break point for register total amounts of processed records if (pr + 1) % BREAK_POINT == 0: page_trans_totals.append( [round(adt, 2) for adt in allow_deduct_totals]) transfer_total_basics.append(round(total_basics, 2)) transfer_totals['allow'].append(round(total_allows, 2)) transfer_totals['deduct'].append(round(total_deducts, 2)) transfer_totals['net'].append( round(total_allows - total_deducts, 2)) # add Company Row emp_data.append(emp_row) total_nets = total_allows - total_deducts # step 5 : prepare allowances/deductions header header = [] # store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow': allow_header.append(allow_deduct['name']) allow_column_index += 1 else: deduct_header.append(allow_deduct['name']) basic_len = len( filter( lambda ad: ad['name_type'] == 'allow' and ad[ 'is_basic_salary_item'], allow_deduct_res)) + 1 allow_len = len( filter( lambda ad: ad['name_type'] == 'allow' and not ad[ 'is_basic_salary_item'], allow_deduct_res)) deduct_len = len( filter(lambda ad: ad['name_type'] == 'deduct', allow_deduct_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 else: additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT) amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data': emp_data, 'headrs': header, 'allow_header': allow_header, 'deduct_header': deduct_header, 'allow_deduct_totals': allow_deduct_totals, 'page_trans_totals': page_trans_totals, 'BREAK_POINT': BREAK_POINT, 'page_trans_totals': lambda index: page_trans_totals[int(index / BREAK_POINT)], 'include_bascic_salary': include_bascic_salary, 'total_basics': round(total_basics, 2), 'transfer_total_basics': lambda index: transfer_total_basics[int(index / BREAK_POINT)], 'len_emp_data': len(emp_data), 'transfer_total': lambda key, index: transfer_totals[key][int(index / BREAK_POINT )], 'include_allow_total': include_allow_total, 'include_deduct_total': include_deduct_total, 'include_net_total': include_net_total, 'total_allows': round(total_allows, 2), 'total_deducts': round(total_deducts, 2), 'total_nets': round(total_nets, 2), 'department_title': department_title, 'allow_column_index': allow_column_index, 'basic_len': basic_len, 'allow_len': allow_len, 'deduct_len': deduct_len, 'additional_rows': additional_rows, 'amount_in_words': amount_in_words, } # print "Final RES>>>>>", res return res
def create_invoice(self, cr, uid, ids, context={}): """ create a financial voucher Contract @return: True """ account_journal_obj = self.pool.get('account.journal') account_obj = self.pool.get('account.account') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') account_period_obj = self.pool.get('account.period') account_budget_obj = self.pool.get('account.budget.confirmation') affairs_account_obj = self.pool.get('admin_affairs.account') admin_affairs_model_obj = self.pool.get('admin.affairs.model') #model_id = admin_affairs_model_obj.search(cr, uid, [('model','=','environment.and.safety')], context=context)[0] #affairs_account = affairs_account_obj.search(cr, uid, [('model_id','=',model_id)], context=context) #if not affairs_account: # raise osv.except_osv(_('Warning !'), _('Please insert Journal For Enviroment and safety')) #affairs_account_id = affairs_account[0] #affairs_account_record = affairs_account_obj.browse(cr, uid, affairs_account_id,context=context) for cont in self.browse(cr, uid, ids, context=context): contract = cont.contract_id #period= account_period_obj.find(cr, uid, dt=contract.date,context=context)[0] #account_ids = account_obj.search(cr, uid, [('code','=',str(contract.category_id.code))], context=context) #journal_ids = account_journal_obj.search(cr, uid, [('name','=',contract.category_id.name_type.name)], context=context) #journal_id = affairs_account_record.journal_id.id #analytic_id = affairs_account_record.analytic_id.id #account_id = affairs_account_record.account_id.id if not contract.category_id.account_id: raise osv.except_osv( _('Warning !'), _('Please insert Category Account Configuration For Enviroment and safety' )) journal_id = contract.category_id.journal_id.id analytic_id = contract.category_id.analytic_id.id account_id = contract.category_id.account_id.id #account_id = account_ids[0] #account_analytic_id=account_analytic_ids[0] voucher_id_dict = {} voucher_line_dict = {} # Creating Voucher / Ratitication voucher_id_dict = { 'amount': cont.final_total, 'journal_id': journal_id, 'type': 'ratification', 'date': time.strftime('%Y-%m-%d'), 'partner_id': contract.partner_id.id, 'account_id': contract.partner_id.property_account_payable.id, 'department_id': contract.department_id.id, 'state': 'draft', 'notes': contract.notes, 'narration': 'Contract or rent No: ' + contract.name, 'amount_in_word': amount_to_text_ar(cont.final_total), } voucher_line_dict = { 'account_id': account_id, 'type': 'dr', 'name': contract.name, } cr.execute('''SELECT distinct a.id, sum(amount_with_tax) as dep_cost FROM public.environment_and_safety as en, public.depat_cost as dep_cost, public.hr_department as hr, public.contract_fees as fes, public.account_analytic_account as a WHERE en.id = fes.contract_id AND dep_cost.department_id = hr.id AND hr.analytic_account_id = a.id AND fes.id = dep_cost.dep_name and fes.id=%s group by a.id ''' % cont.id) res = cr.dictfetchall() #if contract.company_id.code =="HQ": voucher_id_dict = voucher_id_dict voucher_id = voucher_obj.create(cr, uid, voucher_id_dict, context=context) for line in res: voucher_line_dict.update({ 'account_analytic_id': line['id'], 'amount': line['dep_cost'], 'voucher_id': voucher_id, }) voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) """else: voucher_id_dict.update({ 'period_id': period, 'name': contract.name, 'currency_id':43, 'type':'purchase',}) voucher_id = voucher_obj.create(cr, uid,voucher_id_dict,context=context) voucher_line_dict.update({'amount':cont.final_total,'voucher_id':voucher_id,}) voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)""" voucher_state = 'draft' if contract.company_id.affairs_voucher_state: voucher_state = contract.company_id.affairs_voucher_state if voucher_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'account.voucher', voucher_id, voucher_state, cr) voucher_obj.write( cr, uid, voucher_id, { 'type': 'ratification', 'ratification': True, 'state': voucher_state }, context) voucher_number = voucher_obj.browse(cr, uid, voucher_id, context=context).number #copy_attachments(self,cr,uid,ids,'fuel.plan',voucher_id,'account.voucher', context) self.write(cr, uid, ids, {'state': 'done', 'voucher_no': voucher_id}), #contract.write({'fees_total_amount':globals()['mou']}) return True
def _convert(self, amount, currency): amt_en = amount_to_text_ar(amount, 'ar', currency.name, '') return amt_en
def _pars(self, amount): res = amount_to_text_ar(amount) return res
def convert(self, net): print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", net return amount_to_text_ar(net, 'ar')
def _process(self, data, dep_ids=None, outsite_scale=False): allow_column_index = -1 # specify where to show allowance totals department_title = "" page_trans_totals = [] transfer_total_basics = [] transfer_totals = { # store total for printing in each page the summation of last pages records 'loan': [], 'allow_incre': [], 'deduct_incre': [], 'allow_decre': [], 'deduct_decre': [], 'net_pre': [], 'net_curr': [], } res = [] emp_condition = "" year = data['year'] month = data['month'] in_salary_sheet = True ad_type = data['type'] if month==1: pre_month=12 pre_year=year-1 else: pre_month=int(month)-1 pre_year=year # allowance or deduction # paysheet = data['pay_sheet'] # list_to_str = lambda items : ",".join(str(i) for i in items) company_id = data.get('company_id') #raise osv.except_osv(('ERROR'), ('Please enter account for Allowances/deductions for %s')%(data['department_ids'])) print ">>", data['department_ids'] dept_row = { 'emp_name': '', 'emp_curr_total_deduct': 0, 'emp_pre_total_deduct': 0, 'emp_incre_deduct': 0, 'emp_decre_deduct': 0, 'emp_curr_total_allow': 0, 'emp_pre_total_allow': 0, 'emp_incre_allow': 0, 'emp_decre_allow': 0, 'emp_curr_net': 0, 'emp_pre_net': 0, } line_res = dict(map(lambda x: (x, {}), data['department_ids'])) print "prog1>>>",line_res # company_ids_str =list_to_str(company_id) ad_ids_condition = "" # if data['allow_deduct_ids']: # ad_ids_condition = " and public.hr_allowance_deduction_archive.allow_deduct_id in (%s)" %(list_to_str(data['allow_deduct_ids'])) ad_condition = "" # if ad_type : # ad_condition = "and public.hr_allowance_deduction.name_type = '%s' "%(ad_type) self.cr.execute( ''' SELECT hr_payroll_main_archive.department_id as department_id , public.hr_department.name as dep_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.hr_department, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.department_id = hr_department.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.department_id in %s group by hr_payroll_main_archive.department_id, hr_department.name ''' % (month, year,in_salary_sheet, tuple(data['department_ids']))) dep_now_res = self.cr.dictfetchall() ############################################################################################33 self.cr.execute( ''' SELECT hr_payroll_main_archive.department_id as department_id , public.hr_department.name as dep_name , sum(hr_payroll_main_archive.basic_salary) as basic_salary FROM public.hr_department, public.hr_payroll_main_archive WHERE hr_payroll_main_archive.department_id = hr_department.id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_payroll_main_archive.department_id in %s group by hr_payroll_main_archive.department_id, hr_department.name ''' % (pre_month, pre_year,in_salary_sheet, tuple(data['department_ids']))) dep_pre_res = self.cr.dictfetchall() # step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute( ''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (month, year, in_salary_sheet,tuple(data['department_ids']))) allow_deduct_now_res = self.cr.dictfetchall() ####################################################################################### self.cr.execute( ''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s AND hr_employee.id = hr_payroll_main_archive.employee_id order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ''' % (pre_month, pre_year,in_salary_sheet, tuple(data['department_ids']))) allow_deduct_pre_res = self.cr.dictfetchall() # step 3 : get all allowaces/deductions for employees self.cr.execute( ''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.department_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s GROUP by hr_payroll_main_archive.department_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (month, year, in_salary_sheet,tuple(data['department_ids']))) dep_allows_now_res = self.cr.dictfetchall() ################################################################################################ self.cr.execute( ''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.department_id , sum(hr_allowance_deduction_archive.amount) as amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.department_id in %s GROUP by hr_payroll_main_archive.department_id, hr_allowance_deduction_archive.allow_deduct_id ''' % (pre_month, pre_year, in_salary_sheet,tuple(data['department_ids']))) dep_allows_pre_res = self.cr.dictfetchall() # step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in ['deduct'] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow', 'deduct'] # step 4 : prepare table data emp_data = [] # array for store employees data emp_data_pre=[] allow_deduct_totals = [0 for i in range(len(allow_deduct_now_res))] # prepare array for store totals allow_deduct_totals_pre = [0 for i in range(len(allow_deduct_pre_res))] # prepare array for store totals page_trans_totals = [] # array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_basics_pre = 0 total_allows = 0 total_allows_pre = 0 total_deducts = 0 total_deducts_pre = 0 # for j , emp in enumerate(emp_res) : for j, emp in enumerate(dep_now_res): amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 for i, allow_deduct in enumerate(allow_deduct_now_res): # amount_obj = filter(lambda arch : arch['employee_id'] == emp['emp_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'] , emp_allows_res) amount_obj = filter( lambda arch: arch['department_id'] == emp['department_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'], dep_allows_now_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow': emp_total_allow += emp_amount else: emp_total_deduct += emp_amount allow_deduct_totals[i] = allow_deduct_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] # emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 emp_total_allow += emp['basic_salary'] total_allows += emp_total_allow total_deducts += emp_total_deduct emp_row = { 'emp_name': emp['dep_name'], 'emp_id': emp['department_id'], # 'emp_job' : emp['emp_job'], # 'emp_degree':emp['emp_degree'], #'amounts': [round(am, 2) for am in amounts], #'basic_salary': emp['basic_salary'], 'emp_total_deduct': round(emp_total_deduct, 2), 'emp_total_allow': round(emp_total_allow, 2), 'emp_net': round(emp_total_allow - emp_total_deduct, 2), } # here checking break point for register total amounts of processed records #if (j + 1) % BREAK_POINT == 0: # page_trans_totals.append([round(adt, 2) for adt in allow_deduct_totals]) # transfer_total_basics.append(round(total_basics, 2)) # transfer_totals['allow'].append(round(total_allows, 2)) # transfer_totals['deduct'].append(round(total_deducts, 2)) # transfer_totals['net'].append(round(total_allows - total_deducts, 2)) emp_data.append(emp_row) dept_cu_id=emp_row['emp_id'] """dept_row = { 'emp_name': '', 'emp_curr_total_deduct': 0, 'emp_pre_total_deduct': 0, 'emp_incre_deduct': 0, 'emp_decre_deduct': 0, 'emp_curr_total_allow': 0, 'emp_pre_total_allow': 0, 'emp_incre_allow': 0, 'emp_decre_allow': 0, 'emp_curr_net': 0, 'emp_pre_net': 0, }""" print "##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",emp_row['emp_total_deduct'] line_res[dept_cu_id]['emp_name']=emp_row['emp_name'] line_res[dept_cu_id]['emp_curr_total_deduct']=emp_row['emp_total_deduct'] line_res[dept_cu_id]['emp_curr_total_allow']=emp_row['emp_total_allow'] line_res[dept_cu_id]['emp_curr_net']=emp_row['emp_net'] print "line1>>>", emp_data print "line1>>>", line_res total_nets = total_allows - total_deducts ################################################################################################## for j_pre, emp_pre in enumerate(dep_pre_res): amounts_pre = [] allow_amounts_pre = [] deduct_amounts_pre = [] emp_total_allow_pre = 0 emp_total_deduct_pre = 0 for i_pre, allow_deduct_pre in enumerate(allow_deduct_pre_res): # amount_obj = filter(lambda arch : arch['employee_id'] == emp['emp_id'] and arch['allow_deduct_id'] == allow_deduct['allow_deduct_id'] , emp_allows_res) amount_obj_pre = filter( lambda arch: arch['department_id'] == emp_pre['department_id'] and arch['allow_deduct_id'] == allow_deduct_pre['allow_deduct_id'], dep_allows_pre_res) emp_amount_pre = amount_obj_pre and amount_obj_pre[0]['amount'] or 0 if allow_deduct_pre['name_type'] == 'allow': emp_total_allow_pre += emp_amount_pre else: emp_total_deduct_pre += emp_amount_pre allow_deduct_totals_pre[i] = allow_deduct_totals_pre[i] + emp_amount_pre amounts_pre.append(emp_amount_pre) total_basics_pre += emp_pre['basic_salary'] # emp_total_allow += include_bascic_salary and emp['basic_salary'] or 0 emp_total_allow_pre += emp_pre['basic_salary'] total_allows_pre += emp_total_allow_pre total_deducts_pre += emp_total_deduct_pre emp_row_pre = { 'emp_name': emp_pre['dep_name'], 'emp_id': emp_pre['department_id'], # 'emp_job' : emp['emp_job'], # 'emp_degree':emp['emp_degree'], #'amounts': [round(am, 2) for am in amounts_pre], #'basic_salary': emp_pre['basic_salary'], 'emp_total_deduct': round(emp_total_deduct_pre, 2), 'emp_total_allow': round(emp_total_allow_pre, 2), 'emp_pre_net': round(emp_total_allow_pre - emp_total_deduct_pre, 2), } #if emp_pre['department_id']==1821: # raise osv.except_osv(('ERROR'), ('Please enter account for Allowances/deductions for %s')%(emp_row_pre)) # here checking break point for register total amounts of processed records #if (j_pre + 1) % BREAK_POINT == 0: # page_trans_totals.append([round(adt, 2) for adt in allow_deduct_totals]) # transfer_total_basics.append(round(total_basics, 2)) # transfer_totals['allow'].append(round(total_allows, 2)) # transfer_totals['deduct'].append(round(total_deducts, 2)) # transfer_totals['net'].append(round(total_allows - total_deducts, 2)) emp_data_pre.append(emp_row_pre) print "emp>>",emp_row_pre['emp_total_deduct'] dept_pre_id=emp_row_pre['emp_id'] if 'emp_name' not in line_res[dept_pre_id].keys(): line_res[dept_pre_id]['emp_name']=emp_row_pre['emp_name'] line_res[dept_pre_id]['emp_pre_total_deduct']=emp_row_pre['emp_total_deduct'] line_res[dept_pre_id]['emp_pre_total_allow']=emp_row_pre['emp_total_allow'] line_res[dept_pre_id]['emp_pre_net']=emp_row_pre['emp_pre_net'] print "line2>>>", emp_data_pre print "line2>>>", line_res final_list_dept_row=[] total_curr=0 total_pre=0 total_allow_dec=0 total_allow_inc=0 total_dedu_dec=0 total_dedu_inc=0 depart_pool = self.pool.get('hr.department') breake=0 for line in line_res: breake +=1 emp_incre_deduct=0 emp_decre_deduct=0 emp_incre_allow=0 emp_decre_allow=0 if 'emp_name' not in line_res[line].keys(): depart=depart_pool.browse(self.cr,self.uid, line) line_res[line]['emp_name']=depart.name # Check keys if 'emp_pre_total_allow' not in line_res[line].keys(): line_res[line]['emp_pre_total_allow']=0 if 'emp_pre_total_deduct' not in line_res[line].keys(): line_res[line]['emp_pre_total_deduct']=0 if 'emp_curr_total_allow' not in line_res[line].keys(): line_res[line]['emp_curr_total_allow']=0 if 'emp_curr_total_deduct' not in line_res[line].keys(): line_res[line]['emp_curr_total_deduct']=0 if 'emp_curr_net' not in line_res[line].keys(): line_res[line]['emp_curr_net']=0 if 'emp_pre_net' not in line_res[line].keys(): line_res[line]['emp_pre_net']=0 if (line_res[line]['emp_curr_total_allow']-line_res[line]['emp_pre_total_allow']) > 0: emp_incre_allow=line_res[line]['emp_curr_total_allow']-line_res[line]['emp_pre_total_allow'] else: emp_decre_allow=line_res[line]['emp_curr_total_allow']-line_res[line]['emp_pre_total_allow'] if (line_res[line]['emp_curr_total_deduct']-line_res[line]['emp_pre_total_deduct']) > 0: emp_incre_deduct=line_res[line]['emp_curr_total_deduct']-line_res[line]['emp_pre_total_deduct'] else: emp_decre_deduct=line_res[line]['emp_curr_total_deduct']-line_res[line]['emp_pre_total_deduct'] total_curr +=line_res[line]['emp_curr_net'] total_pre +=line_res[line]['emp_pre_net'] total_allow_dec +=emp_decre_allow total_allow_inc +=emp_incre_allow total_dedu_dec +=emp_decre_deduct total_dedu_inc +=emp_incre_deduct final_dept_row = { 'emp_name': line_res[line]['emp_name'], 'emp_curr_total_deduct': line_res[line]['emp_curr_total_deduct'] or 0, 'emp_pre_total_deduct': line_res[line]['emp_pre_total_deduct'] or 0, 'emp_incre_deduct': emp_incre_deduct or 0, 'emp_decre_deduct': emp_decre_deduct or 0, 'emp_curr_total_allow': line_res[line]['emp_curr_total_allow'] or 0, 'emp_pre_total_allow': line_res[line]['emp_pre_total_allow'] or 0, 'emp_incre_allow': emp_incre_allow or 0, 'emp_decre_allow': emp_decre_allow or 0, 'emp_curr_net': line_res[line]['emp_curr_net'] or 0, 'emp_pre_net': line_res[line]['emp_pre_net'] or 0, } final_list_dept_row.append(final_dept_row) if (breake) % BREAK_POINT == 0: transfer_totals['allow_incre'].append(round(total_allow_inc, 2)) transfer_totals['deduct_incre'].append(round(total_dedu_inc, 2)) transfer_totals['allow_decre'].append(round(total_allow_dec, 2)) transfer_totals['deduct_decre'].append(round(total_dedu_dec, 2)) transfer_totals['net_pre'].append(round(total_pre, 2)) transfer_totals['net_curr'].append(round(total_curr, 2)) #print "FFFFFF>>>",final_list_dept_row #print "##>>>",row total_nets_pre = total_allows_pre - total_deducts_pre #print "Curre>>>>>>>>",emp_data_pre #print "Prev>>>>>>>>",emp_data """# step 5 : prepare allowances/deductions header header = [] # store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_now_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow': allow_header.append(allow_deduct['name']) allow_column_index += 1 else: deduct_header.append(allow_deduct['name']) basic_len = len( filter(lambda ad: ad['name_type'] == 'allow' and ad['is_basic_salary_item'], allow_deduct_now_res)) + 1 allow_len = len( filter(lambda ad: ad['name_type'] == 'allow' and not ad['is_basic_salary_item'], allow_deduct_now_res)) deduct_len = len(filter(lambda ad: ad['name_type'] == 'deduct', allow_deduct_now_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 else: additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT)""" amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data': final_list_dept_row, #'headrs': header, #'allow_header': allow_header, #'deduct_header': deduct_header, 'allow_deduct_totals': allow_deduct_totals, #'page_trans_totals': page_trans_totals, 'BREAK_POINT': BREAK_POINT, #'page_trans_totals': lambda index: page_trans_totals[int(index / BREAK_POINT)], #'include_bascic_salary': include_bascic_salary, #'total_basics': round(total_basics, 2), #'transfer_total_basics': lambda index: transfer_total_basics[int(index / BREAK_POINT)], #'len_emp_data': len(emp_data), 'transfer_total': lambda key, index: transfer_totals[key][int(index / BREAK_POINT)], #'include_allow_total': include_allow_total, #'include_deduct_total': include_deduct_total, #'include_net_total': include_net_total, 'total_decre_allows': round(total_allow_dec, 2), 'total_decre_deducts': round(total_dedu_dec, 2), 'total_incre_allows': round(total_allow_inc, 2), 'total_incre_deducts': round(total_dedu_inc, 2), 'total_pre_nets': round(total_pre, 2), 'total_curr_nets': round(total_curr, 2), #'department_title': department_title, #'allow_column_index': allow_column_index, #'basic_len': basic_len, #'allow_len': allow_len, #'deduct_len': deduct_len, #'additional_rows': additional_rows, 'amount_in_words': amount_in_words, } return res
def create_financial_voucher(self, cr, uid, ids, context=None): """ create a financial voucher for Fuel plan. @return: Boolean True """ account_journal_obj = self.pool.get('account.journal') account_obj = self.pool.get('account.account') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') affairs_account_obj = self.pool.get('admin_affairs.account') affairs_model_obj = self.pool.get('admin.affairs.model') for plan in self.browse(cr, uid, ids, context=context): affairs_model_ids = affairs_model_obj.search( cr, uid, [('model', '=', 'fuel.plan')], context=context) affairs_account_ids = affairs_account_obj.search( cr, uid, [('model_id', '=', affairs_model_ids[0])], context=context) if not affairs_account_ids: raise osv.except_osv( _('Error'), _("Please enter the fuel plan accounting configuration")) affairs_account = affairs_account_obj.browse( cr, uid, affairs_account_ids[0], context=context) account_ids = account_obj.search( cr, uid, [('company_id', '=', plan.company_id.id), ('code', '=', str(affairs_account.code))], context=context) journal_ids = account_journal_obj.search( cr, uid, [('company_id', '=', plan.company_id.id), ('name', '=', affairs_account.name_type.name)], context=context) journal_id = journal_ids and journal_ids[ 0] or affairs_account.journal_id.id account_id = account_ids and account_ids[ 0] or affairs_account.account_id.id analytic_id = affairs_account.analytic_id # Creating Voucher / Ratitication cr.execute('''SELECT distinct sum(line.product_qty *line.price_unit) as ful_total,a.id from public.fuel_plan as plan, public.fuel_qty_line as line, public.fuel_quantity as qtun, public.hr_department as h, public.account_analytic_account as a WHERE qtun.plan_id = plan.id AND qtun.id = line.qty_id AND h.id = qtun.department_id AND a.id = h.analytic_account_id and plan.id=%s GROUP BY a.id ''' % plan.id) res = cr.dictfetchall() voucher_id = voucher_obj.create( cr, uid, { 'amount': plan.cost, 'journal_id': journal_id, 'type': 'ratification', 'date': time.strftime('%Y-%m-%d'), 'partner_id': plan.partner_id.id, 'department_id': plan.department_id.id, 'state': 'draft', 'notes': plan.notes, 'narration': 'Fuel plan No: ', 'amount_in_word': amount_to_text_ar(plan.cost), }, context=context) for line in res: voucher_line_dict = { 'voucher_id': voucher_id, 'account_analytic_id': line['id'], 'account_id': account_id, 'amount': line['ful_total'], 'type': 'dr', 'name': plan.name, } voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) # Selecting Voucher Number / Refernece #voucher_number = voucher_obj.browse(cr,uid,voucher_id,context=context).number #################### update workflow state############### vouchser_state = 'draft' if plan.company_id.affairs_voucher_state: vouchser_state = plan.company_id.affairs_voucher_state wf_service = netsvc.LocalService("workflow") if voucher_id: res = wf_service.trg_validate(uid, 'account.voucher', voucher_id, vouchser_state, cr) #if voucher_id and plan.company_id.id!=16: res = wf_service.trg_validate(uid, 'account.voucher',voucher_id, 'prepost', cr) self.write(cr, uid, plan.id, { 'state': 'done', 'voucher_no': voucher_id }, context=context) copy_attachments(self, cr, uid, ids, 'fuel.plan', voucher_id, 'account.voucher', context) return True
def convert(self, amount): return amount_to_text_ar(amount, 'ar')
def _process(self, data, dep_ids=None, outsite_scale=False): allow_column_index = -1 #specify where to show allowance totals department_title = "" page_trans_totals = [] transfer_total_basics = [] transfer_totals= {#store total for printing in each page the summation of last pages records 'loan' : [] , 'allow':[] , 'deduct':[] , 'net' : [] , } emp_condition = "" if data['employee_ids']: emp_ids_str = ','.join(str(i) for i in data['employee_ids']) emp_condition = " and public.hr_payroll_main_archive.employee_id in(%s) " % ( emp_ids_str) year = data['year'] month = data['month'] in_salary_sheet = data['in_salary_sheet'] ad_type = data['type'] #allowance or deduction paysheet = data['pay_sheet'] list_to_str = lambda items: ",".join(str(i) for i in items) company_id = data.get('company_id') company_ids_str = list_to_str(company_id) ad_ids_condition = "" if data['allow_deduct_ids']: ad_ids_condition = " and public.hr_allowance_deduction_archive.allow_deduct_id in (%s)" % ( list_to_str(data['allow_deduct_ids'])) ad_condition = "" if ad_type: ad_condition = "and public.hr_allowance_deduction.name_type = '%s' " % ( ad_type) department_condition = "" if dep_ids: searching_field = outsite_scale and 'location_id' or 'department_id' dep_ids_str = list_to_str(dep_ids) department_condition = "AND public.hr_employee." + searching_field + " in (%s)" % ( dep_ids_str) department_title = self.pool.get('hr.department').read( self.cr, self.uid, [dep_ids[0]], ['name'])[0]['name'] if data['order_by'] == 'degree': order_by = 'seq , emp_name' elif data['order_by'] == 'code': order_by = 'emp_code' else: order_by = 'emp_name' #step 1 : get all employee in passed month , later get ids of passed employees self.cr.execute(''' SELECT hr_payroll_main_archive.employee_id as emp_id , public.hr_employee.name_related as emp_name , hr_payroll_main_archive.basic_salary as basic_salary , public.hr_salary_degree.sequence as seq , public.hr_job.name as emp_job, public.hr_salary_degree.code as emp_degree FROM public.hr_employee, public.hr_payroll_main_archive , public.hr_salary_degree, public.hr_job WHERE hr_payroll_main_archive.employee_id = hr_employee.id AND public.hr_job.id=hr_employee.job_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_salary_degree.id = public.hr_employee.degree_id AND public.hr_payroll_main_archive.company_id in (%s) %s %s order by %s ; ''' % (month, year, in_salary_sheet, company_ids_str, department_condition, emp_condition, order_by)) emp_res = self.cr.dictfetchall() #step 2 : get all allowaces/deductions in passed month , later get ids of passed allowances/deductions self.cr.execute(''' SELECT distinct hr_allowance_deduction_archive.allow_deduct_id , public.hr_allowance_deduction.sequence , public.hr_allowance_deduction.name , public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.is_basic_salary_item FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_allowance_deduction , public.hr_employee WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND public.hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in (%s) AND hr_employee.id = hr_payroll_main_archive.employee_id %s %s %s %s order by public.hr_allowance_deduction.name_type , public.hr_allowance_deduction.sequence ; ''' % (month, year, in_salary_sheet, company_ids_str, department_condition, ad_condition, emp_condition, ad_ids_condition)) allow_deduct_res = self.cr.dictfetchall() #step 3 : get all allowaces/deductions for employees self.cr.execute(''' SELECT hr_allowance_deduction_archive.allow_deduct_id , hr_payroll_main_archive.employee_id , hr_allowance_deduction_archive.amount FROM public.hr_allowance_deduction_archive, public.hr_payroll_main_archive , public.hr_employee , public.hr_allowance_deduction WHERE hr_payroll_main_archive.id = hr_allowance_deduction_archive.main_arch_id AND hr_payroll_main_archive.month = %s AND hr_payroll_main_archive.year = %s AND public.hr_payroll_main_archive.in_salary_sheet= %s AND hr_employee.id = hr_payroll_main_archive.employee_id AND hr_allowance_deduction.id = hr_allowance_deduction_archive.allow_deduct_id AND public.hr_payroll_main_archive.company_id in (%s) %s %s %s %s; ''' % (month, year, in_salary_sheet, company_ids_str, department_condition, ad_condition, emp_condition, ad_ids_condition)) emp_allows_res = self.cr.dictfetchall() #step 3 : check what I need to show in my report !! include_bascic_salary = in_salary_sheet and ad_type not in ['deduct'] include_allow_total = ad_type not in ['deduct'] include_deduct_total = ad_type not in ['allow'] include_net_total = ad_type not in ['allow', 'deduct'] #step 4 : prepare table data emp_data = [] # array for store employees data allow_deduct_totals = [0 for i in range(len(allow_deduct_res)) ] #prepare array for store totals page_trans_totals = [] #array for transfer pages total to next page transfer_total_basics = [] total_basics = 0 total_allows = 0 total_deducts = 0 for j, emp in enumerate(emp_res): amounts = [] allow_amounts = [] deduct_amounts = [] emp_total_allow = 0 emp_total_deduct = 0 for i, allow_deduct in enumerate(allow_deduct_res): amount_obj = filter( lambda arch: arch['employee_id'] == emp['emp_id'] and arch[ 'allow_deduct_id'] == allow_deduct['allow_deduct_id'], emp_allows_res) emp_amount = amount_obj and amount_obj[0]['amount'] or 0 if allow_deduct['name_type'] == 'allow': emp_total_allow += emp_amount else: emp_total_deduct += emp_amount allow_deduct_totals[i] = allow_deduct_totals[i] + emp_amount amounts.append(emp_amount) total_basics += emp['basic_salary'] emp_total_allow += include_bascic_salary and emp[ 'basic_salary'] or 0 total_allows += emp_total_allow total_deducts += emp_total_deduct emp_row = { 'emp_name': emp['emp_name'], 'emp_job': emp['emp_job'], 'emp_degree': emp['emp_degree'], 'amounts': [round(am, 2) for am in amounts], 'basic_salary': emp['basic_salary'], 'emp_total_deduct': round(emp_total_deduct, 2), 'emp_total_allow': round(emp_total_allow, 2), 'emp_net': round(emp_total_allow - emp_total_deduct, 2), } #here checking break point for register total amounts of processed records if (j + 1) % BREAK_POINT == 0: page_trans_totals.append( [round(adt, 2) for adt in allow_deduct_totals]) transfer_total_basics.append(round(total_basics, 2)) transfer_totals['allow'].append(round(total_allows, 2)) transfer_totals['deduct'].append(round(total_deducts, 2)) transfer_totals['net'].append( round(total_allows - total_deducts, 2)) emp_data.append(emp_row) total_nets = total_allows - total_deducts #step 5 : prepare allowances/deductions header header = [] #store headr list for eachpage allow_header = [] deduct_header = [] for allow_deduct in allow_deduct_res: header.append(allow_deduct['name']) if allow_deduct['name_type'] == 'allow': allow_header.append(allow_deduct['name']) allow_column_index += 1 else: deduct_header.append(allow_deduct['name']) basic_len = len( filter( lambda ad: ad['name_type'] == 'allow' and ad[ 'is_basic_salary_item'], allow_deduct_res)) + 1 allow_len = len( filter( lambda ad: ad['name_type'] == 'allow' and not ad[ 'is_basic_salary_item'], allow_deduct_res)) deduct_len = len( filter(lambda ad: ad['name_type'] == 'deduct', allow_deduct_res)) if len(emp_data) % BREAK_POINT == 0: additional_rows = 0 additional_rows = 0 #else: # additional_rows = BREAK_POINT - (len(emp_data) % BREAK_POINT) amount_in_words = amount_to_text_ar(total_nets, 'ar') res = { 'emp_data': emp_data, 'headrs': header, 'allow_header': allow_header, 'deduct_header': deduct_header, 'allow_deduct_totals': allow_deduct_totals, 'page_trans_totals': page_trans_totals, 'BREAK_POINT': BREAK_POINT, 'page_trans_totals': lambda index: page_trans_totals[int(index / BREAK_POINT)], 'include_bascic_salary': include_bascic_salary, 'total_basics': round(total_basics, 2), 'transfer_total_basics': lambda index: transfer_total_basics[int(index / BREAK_POINT)], 'len_emp_data': len(emp_data), 'transfer_total': lambda key, index: transfer_totals[key][int(index / BREAK_POINT)], 'include_allow_total': include_allow_total, 'include_deduct_total': include_deduct_total, 'include_net_total': include_net_total, 'total_allows': round(total_allows, 2), 'total_deducts': round(total_deducts, 2), 'total_nets': round(total_nets, 2), 'department_title': department_title, 'allow_column_index': allow_column_index, 'basic_len': basic_len, 'allow_len': allow_len, 'deduct_len': deduct_len, 'additional_rows': additional_rows, 'amount_in_words': amount_in_words, } return res
def get_amount_written(self, amount_total): return amount_to_text_ar(amount_total)
def convert(self, amount_total): return amount_to_text_ar(amount_total)
def action_create_ratification(self, cr, uid, ids, context={}): """ Method to create account voucher ratification for maintenance amount. @return: Boolean True. """ maitenance_allowances_obj = self.pool.get( 'car.maintenance.allowances.archive') voucher_obj = self.pool.get('account.voucher') voucher_line_obj = self.pool.get('account.voucher.line') affairs_account_obj = self.pool.get('admin_affairs.account') affairs_model_obj = self.pool.get('admin.affairs.model') for record in self.browse(cr, uid, ids, context=context): ar_mount_manag = 0.00 ar_mount_proj = 0.00 sum_list = 0.00 ar_total_pro = 0.00 list1 = [] if record.transfer: raise osv.except_osv( _('Warning'), _("This archive already transfered to the accounting")) model_id = affairs_model_obj.search( cr, uid, [('model', '=', 'car.maintenance')], context=context)[0] affairs_account = affairs_account_obj.search( cr, uid, [('model_id', '=', model_id)], context=context) if not affairs_account: raise osv.except_osv( _('Error'), _("Please enter the Car Maitenance accounting configuration" )) affairs_account = affairs_account_obj.browse(cr, uid, affairs_account[0], context=context) journal_id = affairs_account.journal_id account_id = affairs_account.account_id and affairs_account.account_id.id analytic_id = affairs_account.analytic_id and affairs_account.analytic_id.id cr.execute( 'SELECT sum(l.cost) as cost, a.project,a.id '\ 'FROM car_maintenance_allowances_lines l '\ 'left join hr_department h on (h.id=l.department_id) '\ 'left join account_analytic_account a on (h.analytic_account_id = a.id) '\ 'where l.car_maintenance_allow_id=%s '\ 'GROUP BY a.id, a.project', (record.id,)) res = cr.dictfetchall() ar_mount = 0 for ar in res: if ar['project'] == True: ar_mount_proj += ar['cost'] list1.append(ar_mount_proj) for lis2 in list1: ar_total_pro = lis2 else: ar_mount_manag += ar['cost'] ar_total = ar_mount_manag voucher_dict = { 'company_id': record.company_id.id, 'name': 'Maintenance/CMA/' + ' - ' + str(record.date_from) + ' - ' + str(record.date_to), 'type': 'ratification', 'reference': 'Maintenance/CMA/', 'partner_id': record.partner_id.id, 'account_id': record.partner_id.property_account_payable.id, 'narration': 'Car Maintenace Allowances No: ' + record.name, #'amount_in_word':amount_to_text_ar(ar_total), 'department_id': record.dep.id, } voucher_id = False pro_voucher_id = False vouchers = [] #voucher_id = voucher_obj.create(cr, uid, voucher_dict, context=context) for line in res: if not account_id and not line.request_id.category_id.account_id: raise osv.except_osv( _('Error'), _("Please enter the Car Maitenance accounting configuration" )) if line['project'] and not pro_voucher_id: if not affairs_account.pro_account_id or not affairs_account.pro_journal_id: raise osv.except_osv( _('Warning !'), _('Please insert Journal or Account For Car Maitenance' )) voucher_dict.update( {'journal_id': affairs_account.pro_journal_id.id}) voucher_dict.update( {'amount_in_word': amount_to_text_ar(ar_total_pro)}) pro_voucher_id = voucher_obj.create(cr, uid, voucher_dict, context=context) vouchers.append(pro_voucher_id) if not line['project'] and not voucher_id: if not affairs_account.account_id or not affairs_account.journal_id: raise osv.except_osv( _('Warning !'), _('Please insert Journal or Account For Car Maitenance' )) voucher_dict.update( {'journal_id': affairs_account.journal_id.id}) voucher_dict.update( {'amount_in_word': amount_to_text_ar(ar_total)}) voucher_id = voucher_obj.create(cr, uid, voucher_dict, context=context) vouchers.append(voucher_id) voucher_line_dict = { 'voucher_id': line['project'] and pro_voucher_id or voucher_id, 'account_analytic_id': line['id'], 'account_id': line['project'] and affairs_account.pro_account_id.id or affairs_account.account_id.id, 'amount': line['cost'], 'type': 'dr', 'name': 'Name', } voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) # Selecting Voucher Number / Refernece #voucher_number = self.pool.get('account.voucher').browse(cr,uid,voucher_id) voucher_obj.compute_tax(cr, uid, vouchers, context) ####################workflow state############### voucher_state = 'draft' if record.company_id.affairs_voucher_state: voucher_state = record.company_id.affairs_voucher_state if voucher_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'account.voucher', voucher_id, voucher_state, cr) voucher_obj.write( cr, uid, voucher_id, { 'type': 'ratification', 'ratification': True, 'state': voucher_state }, context) if pro_voucher_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'account.voucher', pro_voucher_id, voucher_state, cr) voucher_obj.write( cr, uid, pro_voucher_id, { 'type': 'ratification', 'ratification': True, 'state': voucher_state }, context) ####################################3 copy_attachments(self, cr, uid, [record.id], 'car.maintenance.allowances.archive', voucher_id, 'account.voucher', context) cr.execute( 'insert into maitenance_voucher (maintain_id,voucher_id) values(%s,%s)', (record.id, voucher_id)) maitenance_allowances_obj.write(cr, uid, record.id, {'transfer': True}, context=context) return True