summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/approval_invoice_date.py
blob: e1bc4c9be70c48ab23e4b7209d29f050e6ea0afb (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
from odoo import models, api, fields
from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import timedelta, date, datetime  
import logging

_logger = logging.getLogger(__name__)

class ApprovalInvoiceDate(models.Model):
    _name = "approval.invoice.date"
    _description = "Approval Invoice Date"
    _rec_name = 'number'

    picking_id = fields.Many2one('stock.picking', string='Picking')
    number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
    date_invoice = fields.Datetime(
        string='Invoice Date',
        copy=False
    )
    date_doc_do = fields.Datetime(
        string='Tanggal Kirim di SJ',
        copy=False
    )
    state = fields.Selection([('draft', 'Draft'), ('done', 'Done'), ('cancel', 'Cancel')], string='State', default='draft', tracking=True)
    approve_date = fields.Datetime(string='Approve Date', copy=False)
    approve_by = fields.Many2one('res.users', string='Approve By', copy=False)
    sale_id = fields.Many2one('sale.order', string='Sale Order')
    partner_id = fields.Many2one('res.partner', string='Partner')
    move_id = fields.Many2one('account.move', string='Invoice')
    note = fields.Char(string='Note')

    def button_approve(self):
        if not self.env.user.is_accounting:
            raise UserError("Hanya Accounting Yang Bisa Approve")
        self.move_id.invoice_date = self.date_doc_do.date()
        self.picking_id.date_doc_kirim = self.date_doc_do
        self.state = 'done'
        self.approve_date = datetime.utcnow()
        self.approve_by = self.env.user.id

    def button_cancel(self):
        self.state = 'cancel'

    @api.model
    def create(self, vals):
        vals['number'] = self.env['ir.sequence'].next_by_code('approval.invoice.date') or '0'
        result = super(ApprovalInvoiceDate, self).create(vals)
        return result