diff options
Diffstat (limited to 'fixco_custom/models/stock_picking.py')
| -rwxr-xr-x | fixco_custom/models/stock_picking.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index a3101d3..526a0eb 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -160,13 +160,49 @@ class StockPicking(models.Model): if self.name.startswith('BU/INT') and self.picking_type_code == 'internal' and self.env.user.id not in [10,15,2] and self.location_dest_id.id == 86: raise UserError(_("Hanya bang rafly hanggara yang bisa validate")) - + res = super(StockPicking, self).button_validate() + if self.name.startswith('BU/IN') and self.origin.startswith('Return of BU/OUT') and self.state == 'done': + self.automatic_reversed_invoice() # if self.name.startswith('BU/OUT') and self.origin.startswith('SO/'): # self.create_invoices() return res + + def automatic_reversed_invoice(self): + origin = self.origin or '' + clean_origin = origin.replace('Return of ', '') + + return_picking = self.env['stock.picking'].search([ + ('name', '=', clean_origin), + ('state', '=', 'done') + ], limit=1) + + if not return_picking: + return False + + account_move = self.env['account.move'].search([ + ('picking_id', '=', return_picking.id), + ('state', '=', 'posted') + ], limit=1) + + if not account_move: + return False + + reversal = self.env['account.move.reversal'].create({ + 'move_ids': [(6, 0, account_move.ids)], + 'date_mode': 'custom', + 'date': fields.Date.context_today(self), + 'refund_method': 'refund', + 'reason': _('Auto reverse from return picking %s') % self.name, + 'company_id': account_move.company_id.id, + }) + + action = reversal.reverse_moves() + + return action + @api.depends('move_lines.origin_returned_move_id') |
