summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-12-22 14:31:37 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-12-22 14:31:37 +0700
commitc6dbde248d5a9c12f7e1f53ce4596f6b5611750a (patch)
treed74e27ecb595d75f1e5e3e0abd5e87dc87d38ce7
parent80afbdeecd286c990ddc80c277287df6c95f5ee8 (diff)
fix suggest po
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py15
-rw-r--r--indoteknik_custom/models/sale_order_line.py14
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml4
-rwxr-xr-xindoteknik_custom/views/sale_order.xml3
4 files changed, 32 insertions, 4 deletions
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index ca0e77ab..9406f85f 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -33,10 +33,21 @@ class PurchaseOrderLine(models.Model):
indent = fields.Boolean(string='Indent', help='centang ini jika barang indent')
is_ltc = fields.Boolean(string='Sudah di LTC', default=False, help='centang ini jika barang sudah di LTC')
note = fields.Char(string='Note')
+ qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved')
+
+ def _compute_qty_reserved(self):
+ for line in self:
+ sale_line = self.env['sale.order.line'].search([
+ ('product_id', '=', line.product_id.id),
+ ('order_id', '=', line.order_id.sale_order_id.id)
+ ])
+
+ reserved_qty = sum(line.qty_reserved for line in sale_line)
+ line.qty_reserved = reserved_qty
def suggest_purchasing(self):
- for line in self:
- if line.qty_available < line.product_qty:
+ for line in self:
+ if line.product_id.qty_available_bandengan + line.qty_reserved < line.product_qty:
line.suggest = 'harus beli'
else:
line.suggest = 'masih cukup'
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index eda003c7..358cbfe2 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -27,7 +27,19 @@ class SaleOrderLine(models.Model):
note_procurement = fields.Char(string='Note Detail', help="Harap diisi jika ada keterangan tambahan dari Procurement, agar dapat dimonitoring")
vendor_subtotal = fields.Float(string='Vendor Subtotal', compute="_compute_vendor_subtotal")
amount_voucher_disc = fields.Float(string='Voucher Discount')
-
+ qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved')
+
+ def _compute_qty_reserved(self):
+ for line in self:
+ stock_moves = self.env['stock.move.line'].search([
+ ('product_id', '=', line.product_id.id),
+ ('picking_id.sale_id', '=', line.order_id.id),
+ ('picking_id.state', 'not in', ['cancel', 'done']),
+ ])
+
+ reserved_qty = sum(move.product_uom_qty for move in stock_moves)
+ line.qty_reserved = reserved_qty
+
def _compute_vendor_subtotal(self):
for line in self:
if line.purchase_price > 0 and line.product_uom_qty > 0:
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index 8e74df4a..21e8c328 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -55,7 +55,9 @@
<field name="qty_incoming" readonly="1" optional="hide"/>
<field name="qty_outgoing" readonly="1" optional="hide"/>
<field name="qty_available" readonly="1" optional="hide"/>
- <field name="suggest" readonly="1"/>
+ <field name="qty_reserved" readonly="1" optional="hide"/>
+ <field name="suggest" readonly="1" widget="badge" decoration-danger="suggest == 'harus beli'" decoration-success="suggest == 'masih cukup'"/>
+ <!-- <field name="suggest" readonly="1"/> -->
</field>
<field name="price_unit" position="after">
<field name="price_vendor" attrs="{'readonly': 1}" optional="hide"/>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 5db2f1e1..18ae4c51 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -105,6 +105,9 @@
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='product_id']" position="before">
<field name="line_no" readonly="1" optional="hide"/>
</xpath>
+ <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='qty_delivered']" position="before">
+ <field name="qty_reserved" readonly="1"/>
+ </xpath>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
<attribute name="options">{'no_create': True}</attribute>
</xpath>