示例#1
0
    def done(self, cr, uid, ids, context=None):
        """ 
        Workflow function to create voucher and calling copy_attachment() method

        @return: Boolean True 
        """
        voucher_id = self.create_voucher(cr, uid, ids, context)
        # Calling copy attachment method
        copy_attachments(self, cr, uid, ids, 'ticket.booking', voucher_id,
                         'account.voucher', context)
        return True
示例#2
0
    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
示例#3
0
    def create_financial_claim(self, cr, uid, ids, context=None):
        """ 
        Workflow function to create a financial claim and change 
        state to done.
 
        @return: Boolean True
        """
        cost = 0.0
        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 hotel_record in self.browse(cr, uid, ids, context=context):
            affairs_model_ids = affairs_model_obj.search(
                cr, uid, [('model', '=', 'hotel.service')], 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 hotel service accounting configuration"
                      ))
            affairs_account = affairs_account_obj.browse(
                cr, uid, affairs_account_ids[0], context=context)
            journal_ids = account_journal_obj.search(
                cr,
                uid, [('company_id', '=', hotel_record.company_id.id),
                      ('name', '=', hotel_record.jou_cat)],
                context=context)
            journal_id = journal_ids and journal_ids[
                0] or affairs_account.journal_id.id
            order = hotel_record.service_type
            # Creating Voucher / Ratitication
            voucher_id = voucher_obj.create(
                cr,
                uid,
                {
                    'amount':
                    hotel_record.cost,
                    #'amount_in_word':amount_to_text_ar(hotel_record.cost),
                    'type':
                    'ratification',
                    'date':
                    time.strftime('%Y-%m-%d'),
                    'partner_id':
                    hotel_record.partner_id.id,
                    'account_id':
                    hotel_record.partner_id.property_account_payable.id,
                    'journal_id':
                    journal_id,
                    'department_id':
                    hotel_record.department_id.id,
                    'state':
                    'draft',
                    'notes':
                    hotel_record.notes,
                    'narration':
                    'Hotel service No : '
                },
                context={})
            for order_record in order:
                account_ids = account_obj.search(
                    cr,
                    uid, [('company_id', '=', hotel_record.company_id.id),
                          ('code', '=', str(order_record.catg_id.code))],
                    context=context)
                account_id = account_ids[0]
                # Creating Voucher / Ratitication
                voucher_line_dict = {
                    'voucher_id':
                    voucher_id,
                    'account_analytic_id':
                    hotel_record.department_id.analytic_account_id.id,
                    'amount':
                    order_record.cost_service,
                    'type':
                    'dr',
                    'journal_id':
                    journal_id,
                    'name':
                    order_record.name,
                }
                if account_id:
                    voucher_line_dict.update({'account_id': account_id})
                voucher_line_obj.create(cr,
                                        uid,
                                        voucher_line_dict,
                                        context=context)
            #################### update workflow state###############
            voucher_state = 'draft'
            if hotel_record.company_id.affairs_voucher_state:
                voucher_state = hotel_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)
            # Selecting Voucher Number / Refernece
            #voucher_number = voucher_obj.browse(cr,uid,voucher_id,context=context).number
            self.write(cr,
                       uid,
                       hotel_record.id, {
                           'state': 'done',
                           'voucher_no': voucher_id
                       },
                       context=context)
            copy_attachments(self, cr, uid, [hotel_record.id], 'hotel.service',
                             voucher_id, 'account.voucher', context)
        return True
示例#4
0
    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
示例#5
0
    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
示例#6
0
    def action_create_ratification(self, cr, uid, ids, context={}):
        """
        Create ratification for Building insurance.
  
        @return: Dictionary 
        """
        wf_service = netsvc.LocalService("workflow")
        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 record in self.browse(cr, uid, ids, context=context):
            affairs_model_ids = affairs_model_obj.search(
                cr,
                uid, [('model', '=', 'building.insurance')],
                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 orm.except_orm(
                    _('Error'),
                    _("Please enter the Building Insurance 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', '=', 'building.insurance')],
                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)
            journal_id = journal_ids[0]
            account_id = account_ids[0]
            analytic_id = affairs_account.analytic_id
            for line in record.insurance_cost_lines:
                voucher_id = voucher_obj.create(
                    cr,
                    uid,
                    {
                        'company_id':
                        record.company_id.id,
                        'journal_id':
                        journal_id and journal_id,
                        'name':
                        'Building/Insurance/' + ' - ' + str(record.date),
                        'type':
                        'ratification',
                        'reference':
                        'Building/Insurance/',
                        'department_id':
                        record.department_id.id,
                        'partner_id':
                        record.partner_id.id,
                        'amount':
                        line.cost,
                        'payment_term':
                        line.payment_term.id,
                        #'amount_in_word':amount_to_text_ar(line.cost),
                        'payment_rate_currency_id':
                        line.currency.id,
                        'narration':
                        'Building insurance No:  ' + record.name +
                        'Currancy: ' + line.currency.name,
                    })

                # Creating Voucher / Ratitication Lines
                voucher_line_obj.create(
                    cr, uid, {
                        'amount':
                        line.cost,
                        'account_id':
                        account_id,
                        'account_analytic_id':
                        analytic_id
                        or record.department_id.analytic_account_id.id,
                        'voucher_id':
                        voucher_id,
                        'type':
                        'dr',
                        'name':
                        'Building Insurance order: ' + record.name,
                    })
                voucher_number = self.pool.get('account.voucher').browse(
                    cr, uid, voucher_id)

                copy_attachments(self, cr, uid, [record.id],
                                 'building.insurance', voucher_id,
                                 'account.voucher', context)
                self.write(cr,
                           uid,
                           ids, {
                               'voucher_no': voucher_number.number,
                               'transfer': True,
                           },
                           context=context)
        return True
示例#7
0
    def done(self, cr, uid, ids, context=None):
        """
        Workflow function to change the state to done and 
        create ratification for Building insurance.

        @return: Boolean True 
        """
        wf_service = netsvc.LocalService("workflow")
        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 record in self.browse(cr, uid, ids, context=context):
            affairs_model_ids = affairs_model_obj.search(
                cr,
                uid, [('model', '=', 'building.insurance')],
                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 orm.except_orm(
                    _('Error'),
                    _("Please enter the Building Insurance 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', '=', 'building.insurance')],
                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)
            journal_id = affairs_account.journal_id.id
            account_id = affairs_account.account_id.id
            analytic_id = affairs_account.analytic_id.id
            build_dict = {'state': 'done'}
            for line in record.insurance_cost_lines:
                voucher_id = voucher_obj.create(
                    cr,
                    uid,
                    {
                        'company_id':
                        record.company_id.id,
                        'journal_id':
                        journal_id and journal_id,
                        'name':
                        'Building/Insurance/' + ' - ' + str(record.date),
                        'type':
                        'ratification',
                        'reference':
                        'Building/Insurance/',
                        #'department_id': record.department_id.id,
                        'partner_id':
                        record.partner_id.id,
                        'amount':
                        line.cost,
                        'payment_term':
                        line.payment_term.id,
                        'payment_rate_currency_id':
                        line.currency.id,
                        'narration':
                        'Building insurance No:  ' + record.name +
                        'Currancy: ' + line.currency.name,
                    })

                # Creating Voucher / Ratitication Lines
                voucher_line_obj.create(
                    cr, uid, {
                        'amount': line.cost,
                        'account_id': account_id,
                        'account_analytic_id': analytic_id,
                        'voucher_id': voucher_id,
                        'type': 'dr',
                        'name': 'Building Insurance order: ' + record.name,
                    })
                #voucher_number = self.pool.get('account.voucher').browse(cr,uid,voucher_id)
                #################### 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],
                                 'building.insurance', voucher_id,
                                 'account.voucher', context)
                build_dict.update({
                    'voucher_no': voucher_id,
                    'transfer': True,
                })
            self.write(cr, uid, ids, build_dict, context=context)
        return True
示例#8
0
    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
示例#9
0
    def done(self, cr, uid, ids, context=None):
        """ 
        Workflow function changes state to done and create account
        voucher.

        @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):
            if record.payment_selection == 'enrich':
                paid = (record.enrich_category.paid_amount + record.cost)
                residual = (record.enrich_category.residual_amount -
                            record.cost)
                #enrich_payment_id = cr.execute("""update payment_enrich set paid_amount=%s , residual_amount=%s where id =%s""",(paid,residual,record.enrich_category.id))
                #details = smart_str('Service Request No:'+record.name+'\n'+record.service_category.name)
                details = 'Building Maitenance No:' + record.name
                enrich_payment_lines_id = payment_enrich_lines_obj.create(
                    cr,
                    uid, {
                        'enrich_id': record.enrich_category.id,
                        'cost': record.cost,
                        'date': record.date,
                        'name': details,
                        'department_id': record.department_id.id,
                    },
                    context=context)
            elif record.payment_selection != 'enrich':
                notes = _("Building Maitenance order: %s") % (record.name)
                affairs_model_ids = affairs_model_obj.search(
                    cr,
                    uid, [('model', '=', 'building.maintenance')],
                    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 orm.except_orm(
                        _('Error'),
                        _("Please enter the building maintenance 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', '=', 'building.maintenance')],
                    context=context)
                account_ids = account_obj.search(
                    cr,
                    uid,
                    [('company_id', '=', record.building_id.company_id.id),
                     ('code', '=', str(affairs_account.code))],
                    context=context)
                journal_ids = account_journal_obj.search(
                    cr,
                    uid,
                    [('company_id', '=', record.building_id.company_id.id),
                     ('name', '=', affairs_account.name_type.name)],
                    context=context)
                journal_id = affairs_account.journal_id.id
                account_id = affairs_account.account_id.id
                analytic_id = affairs_account.analytic_id.id
                # Creating Voucher / Ratitication
                voucher_id = voucher_obj.create(
                    cr, uid, {
                        'amount': record.cost,
                        'type': 'ratification',
                        'date': time.strftime('%Y-%m-%d'),
                        'partner_id': record.partner_id.id,
                        'journal_id': journal_id,
                        'department_id': record.department_id.id,
                        'state': 'draft',
                        'note': record.name,
                        'narration': notes,
                        'company_id': record.company_id.id,
                    })

                # Creating Voucher / Ratitication Lines
                vocher_line_id = voucher_line_obj.create(
                    cr, uid, {
                        'amount': record.cost,
                        'account_id': account_id,
                        'account_analytic_id': analytic_id,
                        'voucher_id': voucher_id,
                        'type': 'dr',
                        'name': 'Building Maintenace order: ' + record.name,
                    })
                #voucher_number = self.pool.get('account.voucher').browse(cr,uid,voucher_id)
                #################### 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],
                                 'building.maintenance', voucher_id,
                                 'account.voucher', context)
                self.write(cr,
                           uid,
                           ids, {'voucher_no': voucher_id},
                           context=context)
        self.write(cr, uid, ids, {'state': 'done'}, context=context)
        return True
    def create_ratification(self, cr, uid, ids, context={}):
        """create ratification for Outsite contract allowances archive 
       @return: Dictionary 
       """
        partner_dict = defaultdict(list)
        emp_payrol = self.pool.get('outsite.contract.main.archive')
        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 record in self.browse(cr, uid, ids, context=context):
            affairs_model_ids = affairs_model_obj.search(
                cr,
                uid, [('model', '=', 'outsite.contract.main.archive')],
                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 Contract Outsite 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', '=', 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)
            journal_id = journal_ids[0]
            account_id = account_ids[0]
            analytic_id = affairs_account.analytic_id
            check_transfer_salary = self.search(
                cr, uid, [('month', '=', record.month),
                          ('year', '=', record.year),
                          ('company_id', '=', record.company_id.id),
                          ('transfer', '=', True)])
            if check_transfer_salary:
                raise osv.except_osv(
                    'ERROR', 'The Payroll For This Month Already Trasfered')
            employ_main_archive = emp_payrol.search(
                cr,
                uid, [('company_id', '=', record.company_id.id),
                      ('year', '=', record.year),
                      ('month', '=', record.month)],
                context=context)
            partner_pay_res = emp_payrol.read(cr,
                                              uid,
                                              employ_main_archive,
                                              ['partner_id'],
                                              context=context)
            for partner in partner_pay_res:
                partner_id = partner['partner_id'][0]
                emp_id = partner['id']
                partner_dict[partner_id].append(emp_id)
            for partner_id in partner_dict.keys():
                cr.execute(
                    '''SELECT 
  sum(oute.gross) as gros
FROM 
  public.outsite_contract_main_archive as oute, 
  public.res_partner as part
WHERE 
  oute.partner_id = part.id and oute.month=%s and oute.year=%s and
  part.id=%s ''', (record.month, record.year, partner_id))
                mount_partner = cr.dictfetchall()
                voucher_dict = {
                    'company_id': record.company_id.id,
                    'department_id': record.department_id.id,
                    'journal_id': journal_id,
                    'name': 'outsiteCOntract/Emp/' + ' - ' + ' - ',
                    'type': 'ratification',
                    'amount': mount_partner[0]['gros'],
                    'reference': 'outsiteCOntract/Emp/',
                    'partner_id': partner_id,
                    'narration': 'Outsie Contract Data: ',
                    'amount_in_word':
                    amount_to_text_ar(mount_partner[0]['gros']),
                }

                voucher_id = voucher_obj.create(cr,
                                                uid,
                                                voucher_dict,
                                                context=context)
                cr.execute(
                    '''SELECT distinct 
  a.id,a.name, 
  sum(outsite.gross) as total
FROM 
  public.outsite_contract_main_archive as outsite, 
  public.hr_department as hr, 
  public.account_analytic_account as a,
  res_partner as part
WHERE 
  outsite.dep_name = hr.id AND outsite.partner_id=part.id and 
  hr.analytic_account_id = a.id and outsite.month=%s
  and outsite.year=%s and outsite.company_id=%s and part.id =%s
  GROUP BY a.id,a.name''', (record.month, record.year, record.company_id.id,
                            partner_id))
                res = cr.dictfetchall()
                for line_id in res:
                    voucher_line_dict = {
                        'voucher_id': voucher_id,
                        'account_analytic_id': line_id['id'],
                        'amount': line_id['total'],
                        'type': 'dr',
                        'name': line_id['name'],
                    }
                    if account_id:
                        voucher_line_dict.update({'account_id': account_id})
                    voucher_line_obj.create(cr,
                                            uid,
                                            voucher_line_dict,
                                            context=context)
                    self.write(cr,
                               uid,
                               record.id, {'transfer': True},
                               context=context)
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'account.voucher', voucher_id,
                                    'approve', cr)
            #voucher_obj.compute_tax(cr, uid,vouchers, context)
            copy_attachments(self, cr, uid, ids,
                             'outsite.contract.main.archive', voucher_id,
                             'account.voucher', context)
        return {}
示例#11
0
    def done(self, cr, uid, ids, context=None):
        """
	Workflow method changes the state to 'done' and transfer the amount to the voucher.
	@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')
        account_period_obj = self.pool.get('account.period')
        payment_enrich_obj = self.pool.get('payment.enrich')
        payment_enrich_lines_obj = self.pool.get('payment.enrich.lines')
        details = ''
        paid = 0.0
        residual = 0.0
        for record in self.browse(cr, uid, ids, context=context):
            if record.cost < 1:
                raise osv.except_osv(_('Error'),
                                     _("Please enter the Right Cost "))
            if record.payment_selection == 'enrich':
                paid = (record.enrich_category.paid_amount + record.cost)
                residual = (record.enrich_category.residual_amount -
                            record.cost)
                enrich_payment_id = cr.execute(
                    """update payment_enrich set paid_amount=%s , residual_amount=%s where id =%s""",
                    (paid, residual, record.enrich_category.id))
                #details = smart_str('Service Request No:'+record.name+'\n'+record.service_category.name)
                details = 'Service Request No:' + record.name
                enrich_payment_lines_id = payment_enrich_lines_obj.create(
                    cr,
                    uid, {
                        'enrich_id': record.enrich_category.id,
                        'cost': record.cost,
                        'date': record.date,
                        'name': details,
                        'department_id': record.department_id.id,
                    },
                    context=context)
            else:
                period = account_period_obj.find(cr,
                                                 uid,
                                                 dt=record.date_of_execution,
                                                 context=context)[0]
                #Account Configuartion for service request
                affairs_model_ids = affairs_model_obj.search(
                    cr,
                    uid, [('model', '=', 'service.request')],
                    context=context)
                affairs_account_ids = affairs_account_obj.search(
                    cr,
                    uid, [('model_id', 'in', affairs_model_ids)],
                    context=context)
                if not affairs_account_ids:
                    raise osv.except_osv(
                        _('Error'),
                        _("Please enter service request accounting configuration"
                          ))
                affairs_account = affairs_account_obj.browse(
                    cr, uid, affairs_account_ids, context=context)
                accoun_model_ids = affairs_model_obj.search(
                    cr,
                    uid, [('model', '=', 'service.request')],
                    context=context)
                account_ids = account_obj.search(
                    cr,
                    uid, [('company_id', '=', record.company_id.id),
                          ('code', '=', str(affairs_account[0].code))],
                    context=context)
                journal_ids = account_journal_obj.search(
                    cr,
                    uid, [('company_id', '=', record.company_id.id),
                          ('name', '=', affairs_account[0].name_type.name)],
                    context=context)
                journal_id = journal_ids and journal_ids[0] or affairs_account[
                    0].journal_id.id
                account_id = account_ids and account_ids[0] or affairs_account[
                    0].account_id.id
                analytic_id = affairs_account[0].analytic_id
                #Account Configuartion per service request category
                category_accounts_ids = account_obj.search(
                    cr,
                    uid, [('company_id', '=',
                           record.service_category.company_id.id),
                          ('code', '=', str(record.service_category.code))],
                    context=context)
                if not category_accounts_ids:
                    raise osv.except_osv(
                        _('Error'),
                        _("Please enter service request category accounting configuration"
                          ))
                cat_account_id = category_accounts_ids[0]
                analytic_account = record.service_category.analytic_id.id
                # Creating Voucher
                if record.service_category.company_id.code == "HQ":
                    voucher_id = voucher_obj.create(
                        cr,
                        uid, {
                            'amount': record.cost,
                            'type': 'ratification',
                            'date': time.strftime('%Y-%m-%d'),
                            'partner_id': record.partner_id.id,
                            'department_id': record.department_id.id,
                            'state': 'draft',
                            'company_id': record.company_id.id,
                            'journal_id': journal_id,
                            'narration': 'Service Request no :' + record.name,
                            'amount_in_word': amount_to_text_ar(record.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.cost,
                        'type': 'dr',
                    }
                    voucher_line = voucher_line_obj.create(
                        cr, uid, voucher_line_dict)
                else:
                    voucher_id = voucher_obj.create(
                        cr,
                        uid, {
                            'company_id':
                            record.service_category.company_id.id,
                            'journal_id':
                            journal_id,
                            'account_id':
                            cat_account_id,
                            'period_id':
                            period,
                            'amount':
                            record.cost,
                            'partner_id':
                            record.partner_id.id,
                            'name':
                            record.name,
                            'currency_id':
                            43,
                            'type':
                            'purchase',
                            'date':
                            record.date_of_execution,
                            'reference':
                            'Service Request' + record.name + '  /  ' +
                            record.service_category.company_id.name + '  /  ' +
                            record.date_of_execution,
                            'narration':
                            'Service Request No:' + record.name,
                        },
                        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.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], 'service.request',
                                 voucher_id, 'account.voucher', context)
                self.write(cr,
                           uid,
                           ids, {'voucher_no': voucher_id},
                           context=context)
        self.write(cr, uid, ids, {'state': 'done'}, context=context)
        return True
示例#12
0
    def done(self, cr, uid, ids, context=None):
        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 record in self.browse(cr, uid, ids):
            notes = _("Building Maitenance order: %s") % (record.name)
            affairs_model_ids = affairs_model_obj.search(
                cr,
                uid, [('model', '=', 'building.maintenance')],
                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 building maintenance 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', '=', 'building.maintenance')],
                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)
            journal_id = journal_ids[0]
            account_id = account_ids[0]
            analytic_id = affairs_account.analytic_id
            # Creating Voucher / Ratitication
            voucher_id = voucher_obj.create(
                cr, uid, {
                    'amount': record.cost,
                    'type': 'ratification',
                    'date': time.strftime('%Y-%m-%d'),
                    'partner_id': record.partner_id.id,
                    'journal_id': journal_id,
                    'department_id': record.department_id.id,
                    'state': 'draft',
                    'note': record.name,
                    'narration': notes,
                    'company_id': record.company_id.id,
                })

            # Creating Voucher / Ratitication Lines
            vocher_line_id = voucher_line_obj.create(
                cr, uid, {
                    'amount': record.cost,
                    'account_id': account_id,
                    'account_analytic_id': analytic_id,
                    'voucher_id': voucher_id,
                    'type': 'dr',
                    'name': 'Building Maintenace order: ' + record.name,
                })
            voucher_number = self.pool.get('account.voucher').browse(
                cr, uid, voucher_id)

        copy_attachments(self, cr, uid, [record.id], 'building.maintenance',
                         voucher_id, 'account.voucher', context)
        self.write(cr,
                   uid,
                   ids, {
                       'state': 'done',
                       'voucher_no': voucher_number.number
                   },
                   context=context)
        return True
示例#13
0
    def action_create_ratification(self, cr, uid, ids, context={}):
        """create ratification for Rented Cars allowances archive 
       @return: Dictionary 
       """

        rented_allowances_obj = self.pool.get('rented.cars.allowances.archive')
        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 record in self.browse(cr, uid, ids, context=context):

            affairs_model_ids = affairs_model_obj.search(
                cr, uid, [('model', '=', 'rented.cars')], 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 Rented Car 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', '=', 'rented.cars')], 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)
            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
            """@declar vir to count the project and non projct voucher"""
            ar_mount_manag = 0.00
            #           ar_mount_proj=0.00
            sum_list = 0.00
            ar_total = 0.00
            #           ar_total_pro=0.00
            list1 = []
            if record.transfer:
                raise osv.except_osv(
                    _('Warning'),
                    _("This archive already transfered to the accounting"))
            """journal_id = affairs_account_record.journal_id
           analytic_id = affairs_account_record.analytic_id
           account_id = affairs_account_record.account_id"""
            #           if not account_id:
            #             raise osv.except_osv(_('Error'), _("Please enter the rented cars account"))

            cr.execute( 'SELECT sum(l.amount_total) as amount_total,a.name as analytic_name,a.id '\
                     'FROM rented_cars_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.rented_cars_allow_id=%s '\
                     'GROUP BY a.id,a.name', (record.id,))
            res = cr.dictfetchall()
            """@count the tow acount of towih project and non projct voucher"""
            for ar in res:
                """if ar['project']==True:
                  ar_mount_proj+=ar['amount_total']
                  list1.append(ar_mount_proj)
                  for lis2 in list1:
                      ar_total_pro=lis2
               else:"""
                ar_mount_manag += ar['amount_total']
                ar_total = ar_mount_manag
            ##########################################################################
            voucher_dict = {
                'company_id':
                record.company_id.id,
                'name':
                'Rented/RCA/' + ' - ' + str(record.month) + ' - ' +
                str(record.year),
                'type':
                'ratification',
                'reference':
                'Rented/RCA/',
                'amount':
                ar_total,
                'partner_id':
                record.partner_id.id,
                'account_id':
                record.partner_id.property_account_payable.id,
                'narration':
                'Rented Cars Allowance 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 = []
            for line in res:
                """if line['project'] and not pro_voucher_id:
                   if not affairs_account_record.pro_account_id or not affairs_account_record.pro_journal_id:
                       raise osv.except_osv(_('Warning !'), _('Please insert Journal or Account For Rented Car'))
                   voucher_dict.update({'journal_id':affairs_account_record.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_record.account_id or not affairs_account_record.journal_id:
                       raise osv.except_osv(_('Warning !'), _('Please insert Journal or Account For Rented Car'))"""
                voucher_dict.update({'journal_id': journal_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': voucher_id,
                    'account_analytic_id': line['id'],
                    'account_id': account_id,
                    'amount': line['amount_total'],
                    'type': 'dr',
                    'name': line['analytic_name'] or '/',
                }
                voucher_line_obj.create(cr,
                                        uid,
                                        voucher_line_dict,
                                        context=context)

            voucher_obj.compute_tax(cr, uid, vouchers, context)

            #################### 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)
#           if pro_voucher_id: res = wf_service.trg_validate(uid, 'account.voucher',pro_voucher_id, 'preresource', cr)
##################
            copy_attachments(self, cr, uid, [record.id],
                             'rented.cars.allowances.archive', voucher_id,
                             'account.voucher', context)
            rented_allowances_obj.write(cr,
                                        uid,
                                        record.id, {
                                            'transfer': True,
                                        },
                                        context=context)
        return True
示例#14
0
    def done(self,cr,uid,ids,context=None):
        """ 
        Workflow function create hospitality service if need, 
        create account voucher with service cost and change 
        state to done.

	    @return: Boolean True 
        """
        wf_service = netsvc.LocalService("workflow")
        hospitality_service_obj=self.pool.get('hospitality.service')
        order_line_obj=self.pool.get('order.lines')
        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')
	occasion_category_obj = self.pool.get('occasion.category') 
        for record in self.browse(cr, uid, ids, context=context):
		# Hospitality Service Creation
		if record.multi_service == 'need_hospitality' : 
            		hospitality_id = hospitality_service_obj.create(cr, uid, {               
                 		'date': time.strftime('%Y-%m-%d'),
                 		'date_of_execution': record.execute_date,
                 		'company_id': record.company_id.id, 
                 		'department_id': record.department_id.id,
                 		'state': 'approved_sc',
				'no_day':record.no_day,
                 		'notes': "This is hospitality service record created From Occasion Service no:"+record.name,

                                    }, context={})
                 	for line in record.occasion_service_order_lines:
                    		order_id_dic = order_line_obj.create(cr,uid,{
                       			'service_sort':line.occasion_service_sort,
                       			'service_type':line.occasion_service_type.id,
                       			'service_qty':line.occasion_service_qty,  
                       			'order_id':hospitality_id,               
                       			 },context=context)
        		hospitality_number = hospitality_service_obj.browse(cr,uid,hospitality_id)
        		self.write(cr, uid, ids, {'hosptality_no':hospitality_number.name})
		# Account Creation & Configuration
		if not record.occasion_partners :
                	raise osv.except_osv(_('Error'), _("Please enter the Occasion Service Partners"))
        	#affairs_model_ids = affairs_model_obj.search(cr, uid, [('model','=','occasion.services')], 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 Occasion Service 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','=','occasion.services')], 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)
        for line in record.occasion_partners :
            if not line.occasion_category.account_id:
            	raise osv.except_osv(_('Warning !'), _('Please insert Category Account Configuration For Enviroment and safety'))
            journal_id = line.occasion_category.journal_id.id
            analytic_id = line.occasion_category.analytic_id.id
            account_id = line.occasion_category.account_id.id
        occasion_voucher = [] 
        occasion_voucher_line=[]
        cr.execute("""SELECT distinct partners_id as partner_id from partner_lines where line_id =%s """%record.id)
        partner_res=cr.dictfetchall()
        for partner in partner_res:
            cost = 0.0
            cr.execute(""" SELECT sum(cost) as total from partner_lines where line_id=%s and partners_id=%s""",(record.id,partner['partner_id']))
			#cr.execute(""" SELECT sum(cost) as total from partner_lines where line_id = %s and partners_id = %s""",(record.id,partner['partner_id']))
            res_cost=cr.dictfetchall()
            for record_cost in res_cost :
				#cost = record_cost['total']
                voucher_dict = {
                                        'type': 'ratification',
                                        'date': time.strftime('%Y-%m-%d'),
                                        'partner_id': partner['partner_id'], 
                                        'department_id': record.department_id.id,
                                        'state': 'draft',
					                    'note':record.name ,
					                    'journal_id':journal_id,
					                    'narration':'Occasion Service record No:'+record.name,
					                    'amount':record_cost['total'],
					#'amount_in_word':amount_to_text_ar(cost),
                                         }
            voucher_id = voucher_obj.create(cr, uid, voucher_dict, context={})
            occasion_voucher.append(voucher_id)
            cr.execute(""" SELECT occasion_category as occasion_category , cost as cost from partner_lines where line_id=%s and partners_id =%s""",(record.id,partner['partner_id']))
            res=cr.dictfetchall()
            for res_account in res :
				#affairs_ids = occasion_category_obj.search(cr,uid,[('id','=',res_account['occasion_category'])],context=context)
				#category_affairs_account = occasion_category_obj.browse(cr, uid, affairs_ids[0], context=context)
        			#accounts_ids = account_obj.search(cr, uid, [('company_id','=',record.company_id.id),('code','=',str(category_affairs_account.code))], context=context)
        			#journals_ids =  account_journal_obj.search(cr, uid, [('company_id','=',record.company_id.id),('name','=',category_affairs_account.name_type.name)], context=context)
        			#cate_journal_id = journals_ids and journals_ids[0]
        			#cate_account_id = accounts_ids and accounts_ids[0]
        			#cate_analytic_id = category_affairs_account.analytic_id
               			voucher_line_dict = {
                  		'account_analytic_id':analytic_id,
                  		'account_id':account_id, 
                  		'amount':res_account['cost'],
                  		'type':'dr',
                  		'name':record.name,
                  
                               }
                        	voucher_line_dict.update({'voucher_id':voucher_id})
                        	voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
            #################### 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],'occasion.services',voucher_id,'account.voucher', context)    
        self.write(cr, uid, ids, {'state':'done','account_voucher_ids':[(6,0,occasion_voucher)]}) 
        return True
示例#15
0
    def action_create_ratification(self,cr,uid,ids,context={}):
       """
	Method transfers the hospitality amount and creates ratification for hospitality service allowances archive.
	@return: Boolean True 
       """
       hospitality_obj = self.pool.get('hospitality.service')
       hospitality_allowances_obj = self.pool.get('hospitality.allowances.archive')
       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 record in self.browse(cr, uid, ids, context=context):
           affairs_model_ids = affairs_model_obj.search(cr, uid, [('model','=','hospitality.service')], 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 hospitality service 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','=','hospitality.service')], 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)
           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 
           cr.execute('''SELECT distinct
  sum(all_line.amount)+(sum(all_line.amount)*17)/100 as hos_sum, 
  a.id
FROM 
  public.hospitality_allowances_archive as hos_allow, 
  public.hospitality_allowances_lines as all_line, 
  public.hr_department as hr, 
  public.account_analytic_account as a
WHERE 
  hos_allow.id = all_line.hospitality_allow_id AND
  hr.id = all_line.department_id AND
  a.id = hr.analytic_account_id   and hos_allow.id=%s
GROUP BY a.id''' %record.id)
           res =  cr.dictfetchall()
           voucher_dict={
                                 'company_id':record.company_id.id,
                                 'department_id':record.departments.id,
                                 'journal_id':journal_id , 
                                 'name': 'Services/HA/'  + ' - ' + record.date_from + ' - ' + record.date_to,
                                 'type':'ratification',
                                 'reference':'Services/HA/' ,
                                 'partner_id' : record.partner_id.id,
                                 'amount':int(record.amount),
                                 'narration' : 'Hospitality service No:  ' + record.name  + '\nThe period between    :  ' + record.date_from + ' and ' + record.date_to,
                                 #'amount_in_word':amount_to_text_ar(record.amount),

                     }
           voucher_id = voucher_obj.create(cr, uid, voucher_dict, context=context)
           
           for line in res:
               
              voucher_line_dict = {
                   'voucher_id':voucher_id,
                   'account_analytic_id':line['id'],
                   'amount':line['hos_sum'],
                   'type':'dr',
                   'name':record.name,
                                 }
              if account_id:
                   voucher_line_dict.update({'account_id':account_id })
              voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
           #################### 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)
           hospitality_allowances_obj.write(cr, uid, record.id,{'transfer':True,} ,context=context)
           cr.execute('insert into hosptial_voucher (hospital_id,voucher_id) values(%s,%s)',(record.id,voucher_id))             
           copy_attachments(self,cr,uid,[record.id],'hospitality.allowances.archive',voucher_id,'account.voucher', context)
       return True
示例#16
0
    def done(self,cr,uid,ids,context=None):
        """
           Workflow method changes the state of To 'done' and transfers the insurance cost to voucher.
           @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 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=0.00
            ar_total_pro=0.00
            list1=[]
            list2=[]
            affairs_model_ids = affairs_model_obj.search(cr, uid, [('model','=','sea.insurance')], 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 sea insurance 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','=','sea.insurance')], 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)
            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
            voucher_id = voucher_obj.create(cr, uid, {
                 'amount': record.total_insurance_cost,
                 'journal_id':journal_id , 
                 'type': 'ratification',
                 'date': time.strftime('%Y-%m-%d'),
                 'partner_id': record.partner_id.id, 
                 'department_id': record.department_id.id,
                 #'amount_in_word':amount_to_text_ar(record.total_insurance_cost),
                 'state': 'draft',
                 'notes': record.notes,
                 'payment_rate_currency_id':record.currency.id,
                 'narration': 'Sea Insurance record No:'+record.name+'\n currency:'+record.currency.name,
                                    }, context={})
            voucher_line_dict = {
                             'voucher_id':voucher_id,
                             'account_analytic_id': analytic_id and analytic_id.id or record.department_id.analytic_account_id.id,
                             'amount':record.total_insurance_cost,
                             'type':'dr',
                             'name': record.name,
                               }
            if account_id:
                voucher_line_dict.update({'account_id':account_id })
            voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
            #################### 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)
            # Selecting Voucher Number / Refernece 
            #voucher_number = voucher_obj.browse(cr,uid,voucher_id,context=context).number
            self.write(cr, uid, record.id,{'state': 'done','voucher_no':voucher_id},context=context)
            copy_attachments(self,cr,uid,ids,'sea.insurance',voucher_id,'account.voucher', context)
        return True
示例#17
0
    def _create_ratification(self, cr, uid, record, partner=None, context={}):
        """
           Method creates account ratification
           @param record: Browse car.operation record
           @param partner: Id of partner
        """
        car_operation_obj = self.pool.get('car.operation')
        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 record.operation_type == 'insurance':
            model = 'car.insurance'
        else:
            model = 'car.license'
        affairs_model_ids = affairs_model_obj.search(cr,
                                                     uid,
                                                     [('model', '=', model)],
                                                     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 Car %s accounting configuration") %
                (record.operation_type, ))
        affairs_account = affairs_account_obj.browse(cr,
                                                     uid,
                                                     affairs_account_ids[0],
                                                     context=context)

        #Prepare account voucher
        voucher_dict = self._prepare_account_voucher(cr,
                                                     uid,
                                                     record,
                                                     affairs_account,
                                                     partner,
                                                     context=context)
        voucher_id = voucher_obj.create(cr, uid, voucher_dict, context=context)
        #################### 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)
        #prepare account voucher line
        voucher_line_dict = self._prepare_account_voucher_line(cr,
                                                               uid,
                                                               voucher_id,
                                                               record,
                                                               affairs_account,
                                                               partner,
                                                               context=context)
        voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)

        voucher_number = voucher_obj.browse(cr,
                                            uid,
                                            voucher_id,
                                            context=context).number
        car_operation_obj.write(
            cr,
            uid, [record.id], {
                'notes': record.notes or '' + str(voucher_number),
            },
            context=context)
        copy_attachments(self, cr, uid, [record.id], 'car.operation',
                         voucher_id, 'account.voucher', context)
    def done(self, cr, uid, ids, context=None):
        """
	Method that changes rhe state to 'done' and transfers the allowances of Contract to the voucher and creates a ratification for them .
	@return: Boolean True
        """

        voucher_obj = self.pool.get('account.voucher')
        voucher_line_obj = self.pool.get('account.voucher.line')
        admin_affairs_model_obj = self.pool.get('admin.affairs.model')
        affairs_account_obj = self.pool.get('admin_affairs.account')
        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 account configuration For Environment and safety'
                  ))
        affairs_account_id = affairs_account[0]

        affairs_account_record = affairs_account_obj.browse(cr,
                                                            uid,
                                                            affairs_account_id,
                                                            context=context)
        for record in self.browse(cr, uid, ids, context=context):
            if not record.allowances_lines_after:
                raise osv.except_osv(
                    _('Partner Amount !'),
                    _('Sorry no partner Amount After Rate To Transfer!'))
            notes = _("Enviroment and Safety allowances Contract: %s") % (
                record.name)

            journal_id = affairs_account_record.journal_id
            analytic_id = affairs_account_record.analytic_id
            account_id = affairs_account_record.account_id

            # Creating Voucher / Ratitication
            voucher_id = voucher_obj.create(
                cr, uid, {
                    'amount': record.amount_total,
                    'type': 'ratification',
                    'date': time.strftime('%Y-%m-%d'),
                    'partner_id': record.partner_id.id,
                    'journal_id': journal_id and journal_id.id,
                    'state': 'draft',
                    'notes': record.notes,
                    'narration': notes,
                    'company_id': record.company_id.id,
                })
            # Creating Voucher / Ratitication Lines
            for line in record.allowances_lines_after:
                '''account_id =line.category_id.account_id
               if not account_id:
                   account_id = line.category_id.parent_id.account_id
                   
               if not account_id:
                   account_id = affairs_account_record.account_id   

               if not account_id:
                  raise osv.except_osv(_('Invalid action !'), _('Please insert Account configuration For Environment and safety Service')) '''

                account_analytic_id = line.category_id.analytic_id
                if not account_analytic_id:
                    account_analytic_id = line.category_id.parent_id.analytic_id

                if not account_analytic_id:
                    account_analytic_id = affairs_account_record.analytic_id

                vocher_line_id = voucher_line_obj.create(
                    cr, uid, {
                        'amount':
                        record.amount_total,
                        'voucher_id':
                        voucher_id,
                        'account_id':
                        account_id and account_id.id,
                        'account_analytic_id':
                        account_analytic_id and account_analytic_id.id,
                        'type':
                        'dr',
                        'name':
                        'environment and Safety allowances :' + record.name,
                    })

# Selecting Voucher Number / Refernece

        voucher_number = self.pool.get('account.voucher').browse(
            cr, uid, voucher_id)

        copy_attachments(self, cr, uid, [record.id],
                         'services.contracts.archive', voucher_id,
                         'account.voucher', context)
        self.write(cr, uid, ids, {
            'state': 'done',
            'transfer': True,
            'voucher_no': voucher_number.number
        })
        return True