From ef46de403cd90ca29f0e7df772fbc7dc7a2c9110 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 28 Jan 2026 15:27:16 +0700 Subject: add bill status PO --- fixco_custom/models/purchase_order.py | 5 +++++ fixco_custom/models/stock_picking.py | 37 ++++++++++++++++++++++++++++++++++- fixco_custom/views/purchase_order.xml | 3 +++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index 07ac1d9..89c1d68 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -59,6 +59,11 @@ class PurchaseOrder(models.Model): discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product', copy=False, default=0.0) bill_date = fields.Date('Bill Date', copy=False) uangmuka_exist = fields.Boolean('Uang Muka Exist', copy=False) + bill_status = fields.Selection([ + ('cancel', 'Cancel'), + ('waiting', 'Waiting Operations'), + ('ready', 'Ready to Bill'), + ], string='Bill Status', copy=False, readonly=True, default='waiting') def _prepare_invoice(self): """Prepare the dict of values to create the new invoice for a purchase order. diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index 04d9504..222c344 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -154,6 +154,33 @@ class StockPicking(models.Model): action = {'type': 'ir.actions.act_window_close'} return action + + def set_po_bill_status(self): + for picking in self: + po = self.env['purchase.order'].search([ + ('name', '=', picking.group_id.name) + ], limit=1) + + if not po or po.state != 'purchase': + continue + + all_pickings = self.env['stock.picking'].search([ + ('group_id', '=', picking.group_id.id), + ('picking_type_code', '=', 'incoming'), + ('state', 'in', ['done', 'cancel', 'ready', 'assigned']), + ]) + + states = all_pickings.mapped('state') + + if all(s == 'cancel' for s in states): + po.bill_status = 'cancel' + + elif any(s in ('assigned', 'ready') for s in states): + po.bill_status = 'waiting' + + else: + po.bill_status = 'ready' + def button_validate(self): if not self.picking_type_code == 'incoming' and not self.name.startswith('BU/IN'): @@ -170,6 +197,9 @@ class StockPicking(models.Model): res = super(StockPicking, self).button_validate() + if self.picking_type_code == 'incoming' and self.name.startswith('BU/IN'): + self.set_po_bill_status() + if ( self.name and self.origin @@ -231,7 +261,12 @@ class StockPicking(models.Model): raise UserError( 'Hanya Accounting yang bisa melakukan cancel karena di po nya sudah ada uang muka' ) - super(StockPicking, self).action_cancel() + res = super(StockPicking, self).action_cancel() + + if self.picking_type_code == 'incoming' and self.name.startswith('BU/IN'): + self.set_po_bill_status() + + return res def action_create_invoice_from_mr(self): """Create the invoice associated to the PO. diff --git a/fixco_custom/views/purchase_order.xml b/fixco_custom/views/purchase_order.xml index 12b7c4b..82b5c79 100644 --- a/fixco_custom/views/purchase_order.xml +++ b/fixco_custom/views/purchase_order.xml @@ -33,6 +33,9 @@ attrs="{'invisible': [('partner_id', '!=', 270)]}" icon="fa-cloud-download"/> + + + -- cgit v1.2.3