summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_outstanding.py
blob: 018ab0ec5e079ad2eef781c36a4cb6883e9568da (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
from odoo import fields, models, api, tools


class PurchaseOutstanding(models.Model):
    _name = 'purchase.outstanding'
    _auto = False
    _rec_name = 'product_id'

    id = fields.Integer()
    order_id = fields.Many2one('purchase.order', string='Nomor PO')
    partner_id = fields.Many2one('res.partner', String='Vendor')
    user_id = fields.Many2one('res.users', string='Purchaser')
    date_order = fields.Datetime(string="Date Order")
    po_state = fields.Char(string='State')
    po_status = fields.Char(string='PO Status')
    product_id = fields.Many2one('product.product', string='Product')
    product_uom_qty = fields.Integer(string='Qty PO')
    qty_received = fields.Integer(string='Qty Received')

    def init(self):
        tools.drop_view_if_exists(self.env.cr, self._table)
        self.env.cr.execute("""
                            CREATE OR REPLACE VIEW %s AS(
                                select pol.id as id, po.id as order_id, po.partner_id, po.user_id,
                                po.date_order, po.state as po_state, po.po_status,
                                pol.product_id, pol.product_uom_qty, pol.qty_received 
                                from purchase_order_line pol
                                join purchase_order po on po.id = pol.order_id
                                where 1=1
                                and pol.product_uom_qty <> pol.qty_received 
                                and po_status in ('sebagian','menunggu')
                            )
                            """ % self._table)