summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-11-26 14:15:31 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-11-26 14:15:31 +0700
commit23c04baabdfe5df35d4aea2849004f86b285ce32 (patch)
treec6d0df31faa25f5ea2f730f7121c4857d006e53f
parent447c98f3079af31a850dd3898190da1063f45cf0 (diff)
before testing outgoing and incoming v2
-rwxr-xr-xindoteknik_custom/models/product_template.py79
1 files changed, 59 insertions, 20 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 25473ab8..3642c0d7 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1,4 +1,4 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, tools, _
from datetime import datetime, timedelta, date
from odoo.exceptions import UserError
import logging
@@ -482,33 +482,48 @@ class ProductProduct(models.Model):
def _get_qty_incoming_bandengan(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ qty = self.env['stock.move'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ('state', 'not in', ['done', 'cancel', 'draft'])
+ ],
+ fields=['product_uom_qty'],
+ groupby=[]
+ )[0].get('product_uom_qty', 0.0)
product.qty_incoming_bandengan = qty
def _get_qty_incoming_bandengan_with_exclude(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ qty = self.env['stock.move'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ('state', 'not in', ['done', 'cancel', 'draft'])
+ ],
+ fields=['product_uom_qty'],
+ groupby=[]
+ )[0].get('product_uom_qty', 0.0)
product.qty_incoming_bandengan = qty
def _get_qty_outgoing_bandengan(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', '=', 5),
- ('location_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ # qty_outgoing = self.env['stock.move'].search([
+ # ('product_id', '=', product.id),
+ # # ('location_dest_id', '=', 5),
+ # ('location_id', 'in', [57, 83]),
+ # ('state', 'not in', ['done', 'cancel', 'draft'])
+ # ])
+ # qty = sum(qty_outgoing.mapped('product_uom_qty'))
+ qty = self.env['stock.move'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_id', 'in', [57, 83]),
+ ('state', 'not in', ['done', 'cancel', 'draft'])
+ ],
+ fields=['product_uom_qty'],
+ groupby=[]
+ )[0].get('product_uom_qty', 0.0)
product.qty_outgoing_bandengan = qty
def _get_qty_onhand_bandengan(self):
@@ -598,3 +613,27 @@ class ProductProduct(models.Model):
('end_date', '>=', current_time)
], limit=1)
return pricelist
+
+
+class OutstandingMove(models.Model):
+ _name = 'v.move.oustanding'
+ _auto = False
+ _rec_name = 'id'
+
+ id = fields.Integer(string='ID')
+ product_id = fields.Many2one('product.product', string='Product')
+ reference = fields.Char(string='Reference', help='Nomor Dokumen terkait')
+ qty_need = fields.Float(string='Qty Need', help='Qty yang akan outgoing / incoming')
+ qty_reserved = fields.Float(string='Qty Reserved', help='Qty yang sudah ter-reserved jika outgoing')
+
+ def init(self):
+ tools.drop_view_if_exists(self.env.cr, self._table)
+ self.env.cr.execute("""
+ CREATE OR REPLACE VIEW %s AS
+ select sml.id, sm.reference, sm.product_id,
+ sm.product_uom_qty as qty_need, sml.product_uom_qty as qty_reserved
+ from stock_move sm
+ join stock_move_line sml on sml.move_id = sm.id
+ where 1=1
+ and sm.state not in('done', 'cancel', 'draft')
+ """ % self._table)