summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-02 15:11:16 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-02 15:11:16 +0700
commit0d5114af051fed9575bc0d108a0fa14a13875f1b (patch)
tree347f026b13dd75726e1a37e2c90d4e0d446f4bc0
parent52016c0ba728b92c913b560d0302a07f12ddfb9c (diff)
add so status for filter outstanding sales
-rwxr-xr-xindoteknik_custom/models/sale_order.py63
-rwxr-xr-xindoteknik_custom/views/sale_order.xml12
2 files changed, 74 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index f21a80fe..7f25f946 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1,9 +1,11 @@
from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools.misc import formatLang, get_lang
-
+import logging
import warnings
+_logger = logging.getLogger(__name__)
+
class SaleOrder(models.Model):
_inherit = "sale.order"
@@ -42,6 +44,65 @@ class SaleOrder(models.Model):
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="Dipakai untuk alamat tempel")
fee_third_party = fields.Float('Fee Pihak Ketiga')
+ so_status = fields.Selection([
+ ('terproses', 'Terproses'),
+ ('sebagian', 'Sebagian Diproses'),
+ ('menunggu', 'Menunggu Diproses'),
+ ])
+
+ def calculate_so_status_beginning(self):
+ so_state = ['sale']
+ sales = self.env['sale.order'].search([
+ ('state', 'in', so_state),# must add validation so_status
+ ])
+ for sale in sales:
+ sum_qty_ship = sum_qty_so = 0
+ have_outstanding_pick = False
+
+ for pick in sale.picking_ids:
+ if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting':
+ have_outstanding_pick = True
+
+ for so_line in sale.order_line:
+ sum_qty_so += so_line.product_uom_qty
+ sum_qty_ship += so_line.qty_delivered
+
+ if have_outstanding_pick:
+ if sum_qty_so > sum_qty_ship > 0:
+ sale.so_status = 'sebagian'
+ else:
+ sale.so_status = 'menunggu'
+ else:
+ sale.so_status = 'terproses'
+ _logger.info('Calculate SO Status %s' % sale.id)
+
+ def calculate_so_status(self):
+ so_state = ['sale']
+ so_status = ['sebagian', 'menunggu']
+ sales = self.env['sale.order'].search([
+ ('state', 'in', so_state),
+ ('so_status', 'in', so_status),
+ ])
+ for sale in sales:
+ sum_qty_ship = sum_qty_so = 0
+ have_outstanding_pick = False
+
+ for pick in sale.pciking_ids:
+ if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting':
+ have_outstanding_pick = True
+
+ for so_line in sale.order_line:
+ sum_qty_so += so_line.product_uom_qty
+ sum_qty_ship += so_line.qty_delivered
+
+ if have_outstanding_pick:
+ if sum_qty_so > sum_qty_ship > 0:
+ sale.so_status = 'sebagian'
+ else:
+ sale.so_status = 'menunggu'
+ else:
+ sale.so_status = 'terproses'
+ _logger.info('Calculate SO Status %s' % sale.id)
@api.onchange('partner_shipping_id')
def onchange_partner_shipping(self):
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index ea0cc569..c3bbf8c3 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -72,5 +72,17 @@
</field>
</field>
</record>
+ <record id="sales_order_tree_view_inherit" model="ir.ui.view">
+ <field name="name">Sale Order</field>
+ <field name="model">sale.order</field>
+ <field name="inherit_id" ref="sale.view_order_tree"/>
+ <field name="arch" type="xml">
+ <field name="state" position="after">
+ <field name="approval_status" />
+ <field name="client_order_ref"/>
+ <field name="so_status"/>
+ </field>
+ </field>
+ </record>
</data>
</odoo> \ No newline at end of file