Esempio n. 1
0
    def button_confirm(self):
        self.ensure_one()
        if self.type == 'parsial':
            self.ajuan_id.write({
                'type_pencairan': 'parsial',
                'pencairan_id': self.id
            })
            self.post_mesages_pencairan('Confirmed')
            for uudps in self.uudp_ids:
                uudps.write({'tgl_pencairan': self.tgl_pencairan})
            return self.write({'state': 'confirm_parsial'})
        elif self.type == 'once':
            for ajuan in self.uudp_ids:
                datas = {'type_pencairan': 'once'}
                # ketika confirm langsung assign
                # if ajuan.cara_bayar == 'cash' :
                datas.update({
                    'total_pencairan':
                    ajuan.total_ajuan,
                    'pencairan_id':
                    self.id,
                    'tgl_pencairan':
                    self.tgl_pencairan,
                    'terbilang':
                    terbilang.terbilang(int(round(ajuan.total_ajuan, 0)),
                                        "IDR", "id"),
                })

                ajuan.write(datas)
            self.post_mesages_pencairan('Confirmed')
            return self.write({'state': 'confirm_once'})
Esempio n. 2
0
    def button_done_once(self):
        self.ensure_one()
        total_ajuan = 0
        now = datetime.datetime.now()
        if self.uudp_ids:
            for ajuan in self.uudp_ids:
                tgl_pencairan = self.tgl_pencairan
                if ajuan.tgl_pencairan:
                    tgl_pencairan = ajuan.tgl_pencairan
                #  tansfer tidak langsung create jurnal
                if ajuan.cara_bayar == 'transfer':
                    datas = {
                        'total_pencairan':
                        ajuan.total_ajuan,
                        'state':
                        'confirm_accounting',
                        'pencairan_id':
                        self.id,
                        'tgl_pencairan':
                        tgl_pencairan,
                        'terbilang':
                        terbilang.terbilang(int(round(ajuan.total_ajuan, 0)),
                                            "IDR", "id"),
                    }
                    ajuan.write(datas)
                    continue
                account_move = self.env['account.move']
                reference = self.name + ' - ' + ajuan.name
                account_move_line = []
                total_kredit = 0
                # not_confirmed_accounting = ajuan.uudp_ids.filtered(lambda x: x.state != 'confirm_accounting')
                # if not_confirmed_accounting :
                #     raise AccessError(_('Ada ajuan yang belum confirm accounting !') )
                partner = ajuan.responsible_id.partner_id.id
                for juan in ajuan.uudp_ids:
                    if juan.partner_id:
                        partner = juan.partner_id.id
                    tag_id = False
                    if juan.store_id and juan.store_id.account_analytic_tag_id:
                        tag_id = [(6, 0,
                                   [juan.store_id.account_analytic_tag_id.id])]
                    if ajuan.type == 'pengajuan':
                        debit = ajuan.coa_debit
                        if not debit:
                            raise AccessError(
                                _('Debit acount pada ajuan %s belum diisi !') %
                                (ajuan.name))
                    else:
                        debit = juan.coa_debit
                        if not debit:
                            raise AccessError(
                                _('Debit Account lines pada ajuan %s belum diisi !'
                                  ) % (ajuan.name))
                    #account debit
                    if juan.total > 0.0:
                        account_move_line.append((0, 0, {
                            'account_id':
                            debit.id,
                            'partner_id':
                            partner,
                            'analytic_account_id':
                            ajuan.department_id.analytic_account_id.id
                            or False,
                            'analytic_tag_ids':
                            tag_id,
                            'name':
                            juan.description,
                            'debit':
                            juan.total,
                            'date':
                            tgl_pencairan,
                            'date_maturity':
                            tgl_pencairan
                        }))
                    elif juan.total < 0.0:
                        account_move_line.append((0, 0, {
                            'account_id':
                            debit.id,
                            'partner_id':
                            partner,
                            'analytic_account_id':
                            ajuan.department_id.analytic_account_id.id
                            or False,
                            'analytic_tag_ids':
                            tag_id,
                            'name':
                            juan.description,
                            'credit':
                            -juan.total,
                            'date':
                            tgl_pencairan,
                            'date_maturity':
                            tgl_pencairan
                        }))
                #account credit bank / hutang
                notes = ajuan.notes
                if not notes:
                    notes = self.coa_kredit.name
                account_move_line.append((0, 0, {
                    'account_id':
                    self.coa_kredit.id,
                    'partner_id':
                    ajuan.responsible_id.partner_id.id,
                    'analytic_account_id':
                    ajuan.department_id.analytic_account_id.id or False,
                    'name':
                    notes,
                    'credit':
                    ajuan.total_ajuan,
                    'date':
                    tgl_pencairan,
                    'date_maturity':
                    tgl_pencairan
                }))

                journal_id = ajuan.pencairan_id.journal_id
                if not journal_id:
                    journal_id = self.env['account.move'].sudo().search(
                        [('ref', 'ilike', '%' + ajuan.name + '%')], limit=1)
                    if not journal_id:
                        raise AccessError(
                            _('Journal pencairan tidak ditemukan !'))
                    journal_id = journal_id.journal_id
                data = {
                    "journal_id":
                    self.journal_id.id,
                    "ref":
                    self.name + ' - ' + ajuan.name,
                    "date":
                    tgl_pencairan,
                    "company_id":
                    self.company_id.id,
                    "narration":
                    self.notes,
                    "terbilang":
                    terbilang.terbilang(int(round(ajuan.total_ajuan, 0)),
                                        "IDR", "id"),
                    "line_ids":
                    account_move_line,
                }

                journal_entry = self.env['account.move'].create(data)
                if journal_entry:
                    journal_entry.post()
                    # self.write_state_line('done')
                    ajuan.write({'selesai': True})
                    self.post_mesages_pencairan('Done')
                    return self.write({
                        'state': 'done',
                        'journal_entry_id': journal_entry.id
                    })
                else:
                    raise AccessError(_('Gagal membuat journal entry'))
                return self.write({'state': 'done'})
Esempio n. 3
0
    def button_validate(self):
        self.ensure_one()
        total_ajuan = 0.0
        now = datetime.datetime.now()
        partner = self.responsible_id.partner_id.id
        if self.state != 'confirm_accounting' or not self.pencairan_id:
            raise AccessError(_('Ajuan %s belum confirm accounting atau belum dijadwalkan pencairan!') % (self.name))

        reference =  self.pencairan_id.name + ' - ' + self.name
        account_move = self.env['account.move']
        datas_form = {'state' : 'done'}
        # cek jika journal sdh di create
        journal_exist = account_move.sudo().search([('ref','=',reference)])
        if not journal_exist :
            account_move_line = []
            for juan in self.uudp_ids :
                if juan.partner_id :
                    partner = juan.partner_id.id
                tag_id = False
                if juan.store_id and juan.store_id.account_analytic_tag_id :
                    tag_id = [(6, 0, [juan.store_id.account_analytic_tag_id.id])]
                if self.type == 'pengajuan' :
                    debit = self.coa_debit
                    if not debit :
                        raise AccessError(_('Debit acount pada ajuan %s belum diisi !') % (self.name) )
                else :
                    debit = juan.coa_debit
                    if not debit :
                        raise AccessError(_('Debit Account lines pada ajuan %s belum diisi !') % (self.name) )
                #account debit
                if juan.sub_total > 0.0 :
                    account_move_line.append((0, 0 ,{'account_id'       : debit.id,
                                                    'partner_id'        : partner,
                                                    'analytic_account_id' : self.department_id.analytic_account_id.id or False,
                                                    'analytic_tag_ids'  : tag_id,
                                                    'name'              : juan.description,
                                                    'debit'             : juan.sub_total,
                                                    'company_id'        : self.company_id.id,
                                                    'date'              : self.pencairan_id.tgl_pencairan,
                                                    'date_maturity'     : self.pencairan_id.tgl_pencairan}))
                elif juan.sub_total < 0.0 :
                    account_move_line.append((0, 0 ,{'account_id'       : debit.id,
                                                    'partner_id'        : partner,
                                                    'analytic_account_id' : self.department_id.analytic_account_id.id or False,
                                                    'analytic_tag_ids'  : tag_id,
                                                    'name'              : juan.description,
                                                    'credit'            : -juan.sub_total,
                                                    'date'              : self.pencairan_id.tgl_pencairan,
                                                    'company_id'        : self.company_id.id,
                                                    'date_maturity'     : self.pencairan_id.tgl_pencairan}))
                #account credit bank / hutang
                notes = self.notes
                if not notes :
                    notes= self.coa_kredit.name
            account_move_line.append((0, 0 ,{'account_id'       : self.pencairan_id.coa_kredit.id,
                                            'partner_id'        : self.responsible_id.partner_id.id,
                                            'analytic_account_id' : self.department_id.analytic_account_id.id or False,
                                            'name'              : notes,
                                            'credit'            : self.total_ajuan,
                                            'company_id'        : self.company_id.id,
                                            'date'              : self.pencairan_id.tgl_pencairan,
                                            'date_maturity'     : self.pencairan_id.tgl_pencairan}))

            data={"journal_id": self.pencairan_id.journal_id.id,
                  "ref": reference,
                  "date": self.pencairan_id.tgl_pencairan,
                  "company_id": self.company_id.id,
                  "narration": self.pencairan_id.notes,
                  "terbilang" : terbilang.terbilang(int(round(self.total_ajuan,0)), "IDR", "id"),
                  "line_ids":account_move_line,}

            journal_entry = account_move.create(data)
            journal_entry.post()
            datas_form.update({'journal_entry_id' : journal_entry.id})

        self.post_mesages_uudp('Done')
        return self.write(datas_form)
Esempio n. 4
0
    def action_pencairan(self):
        nominal = self.nominal
        sisa_pencairan = self.uudp_pencairan_id.sisa_pencairan_parsial
        not_confirmed_accounting = self.uudp_pencairan_id.uudp_ids.filtered(
            lambda x: x.state != 'confirm_accounting')
        if not_confirmed_accounting:
            raise AccessError(_('Ada ajuan yang belum confirm accounting !'))
        now = datetime.datetime.now()
        if nominal <= 0:
            raise UserError(_('Nominal pencairan tidak boleh 0!'))

        if not self.uudp_pencairan_id.sisa_pencairan_parsial and not self.uudp_pencairan_id.journal_entry_ids and nominal > self.uudp_pencairan_id.ajuan_id.total_ajuan:
            raise UserError(
                _('Nominal pencairan tidak boleh melebihi total ajuan!'))

        if self.uudp_pencairan_id.journal_entry_ids and nominal > sisa_pencairan:
            raise UserError(
                _('Nominal pencairan tidak boleh melebihi sisa nominal ajuan yang belum dicairkan!'
                  ))

        # self._cr.execute("SELECT description FROM uudp_detail WHERE uudp_id=%s" , ( [(self.uudp_pencairan_id.ajuan_id.id)] ))
        # descriptions = self._cr.dictfetchall()
        # des = []
        # for d in descriptions:
        # 	des.append(str(d['description']))

        # all_desciptions = ' '.join(des)
        if not self.uudp_pencairan_id.coa_kredit:
            raise UserError(_('Credit account belum diisi !'))

        account_move_line = []
        debt = self.uudp_pencairan_id.ajuan_id.coa_debit
        if self.debit_account_id:
            debt = self.debit_account_id
        label_debit = self.debit_account_notes
        if not label_debit:
            label_debit = debt.name
        label_credit = self.notes
        if not label_credit:
            label_credit = self.uudp_pencairan_id.coa_kredit.name
        #account debit
        account_move_line.append((0, 0, {
            'account_id':
            debt.id,
            'partner_id':
            self.uudp_pencairan_id.ajuan_id.responsible_id.partner_id.id,
            'analytic_account_id':
            self.uudp_pencairan_id.ajuan_id.department_id.analytic_account_id.
            id,
            'name':
            label_debit,
            'debit':
            self.nominal,
            'date_maturity':
            self.date
        }))

        #account credit
        account_move_line.append((0, 0, {
            'account_id':
            self.uudp_pencairan_id.coa_kredit.id,
            'partner_id':
            self.uudp_pencairan_id.ajuan_id.responsible_id.partner_id.id,
            'analytic_account_id':
            self.uudp_pencairan_id.ajuan_id.department_id.analytic_account_id.
            id,
            'name':
            label_credit,
            'credit':
            self.nominal,
            'date_maturity':
            self.date
        }))

        #create journal entry
        data = {
            "uudp_pencairan_id":
            self.uudp_pencairan_id.id,
            "journal_id":
            self.uudp_pencairan_id.journal_id.id,
            "ref":
            self.uudp_pencairan_id.name,
            "date":
            self.date,
            "company_id":
            self.uudp_pencairan_id.company_id.id,
            "terbilang":
            terbilang.terbilang(int(round(self.nominal, 0)), "IDR", "id"),
            "line_ids":
            account_move_line,
        }

        journal_entry = self.env['account.move'].create(data)
        if journal_entry:
            journal_entry.post()
            total = 0
            sisa = 0
            for journal in self.uudp_pencairan_id.journal_entry_ids:
                total += journal.amount

            sisa = self.uudp_pencairan_id.ajuan_id.total_ajuan - total

            self.uudp_pencairan_id.write({'sisa_pencairan_parsial': sisa})
            self.uudp_pencairan_id.ajuan_id.write({'total_pencairan': total})

            if total == self.uudp_pencairan_id.ajuan_id.total_ajuan:
                self.uudp_pencairan_id.ajuan_id.write({'state': 'done'})
                self.uudp_pencairan_id.write({'state': 'done'})
        return journal_entry