diff options
Diffstat (limited to 'fixco_custom/models/stock_picking.py')
| -rwxr-xr-x | fixco_custom/models/stock_picking.py | 37 |
1 files changed, 36 insertions, 1 deletions
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. |
