summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/account_move.py
blob: db4886f4e8160377cc63697293ea5b0c62a50326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from odoo import models, api, fields
from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import timedelta, date


class AccountMove(models.Model):
    _inherit = 'account.move'
    invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due")
    date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak")
    last_log_fp = fields.Char(string="Log Terakhir Faktur Pajak")
    # use for industry business
    date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur')
    resi_tukar_faktur = fields.Char(string='Resi Faktur')
    date_terima_tukar_faktur = fields.Date(string='Terima Faktur')
    shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur')

    def unlink(self):
        res = super(AccountMove, self).unlink()
        if not self.env.user.is_accounting:
            raise UserError('Hanya Accounting yang bisa delete')
        return res

    def button_cancel(self):
        res = super(AccountMove, self).button_cancel()
        if self.id and not self.env.user.is_accounting:
            raise UserError('Hanya Accounting yang bisa Cancel')
        return res

    def button_draft(self):
        res = super(AccountMove, self).button_draft()
        if not self.env.user.is_accounting:
            raise UserError('Hanya Accounting yang bisa Reset to Draft')
        return res

    def action_post(self):
        res = super(AccountMove, self).action_post()
        # if not self.env.user.is_accounting:
        #     raise UserError('Hanya Accounting yang bisa Posting')
        return res
    
    def _compute_invoice_day_to_due(self):
        for invoice in self:
            invoice_day_to_due = 0
            if invoice.payment_state not in ['paid', 'in_payment', 'reversed'] and invoice.invoice_date_due:
                invoice_day_to_due = invoice.invoice_date_due - date.today()
                invoice_day_to_due = invoice_day_to_due.days
            invoice.invoice_day_to_due = invoice_day_to_due

    @api.onchange('date_kirim_tukar_faktur')
    def change_date_kirim_tukar_faktur(self):
        for invoice in self:
            if not invoice.date_kirim_tukar_faktur:
                return
            tukar_date = invoice.date_kirim_tukar_faktur
            term = invoice.invoice_payment_term_id
            add_days = 0
            for line in term.line_ids:
                add_days += line.days
            due_date = tukar_date + timedelta(days=add_days)
            invoice.invoice_date_due = due_date

    @api.onchange('date_terima_tukar_faktur')
    def change_date_terima_tukar_faktur(self):
        for invoice in self:
            if not invoice.date_terima_tukar_faktur:
                return
            tukar_date = invoice.date_terima_tukar_faktur
            term = invoice.invoice_payment_term_id
            add_days = 0
            for line in term.line_ids:
                add_days += line.days
            due_date = tukar_date + timedelta(days=add_days)
            invoice.invoice_date_due = due_date