diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-22 13:36:43 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-22 13:36:43 +0700 |
| commit | 74bc0544d9789479f599e808930e01ecea7fbf22 (patch) | |
| tree | ef11ccc1620ab31ee1b560c8b16f0552041a7742 /fixco_custom/models/stock_picking.py | |
| parent | b03b5e7d3ab83db6f26610490fc2a4e7dc4d3d9c (diff) | |
push
Diffstat (limited to 'fixco_custom/models/stock_picking.py')
| -rwxr-xr-x | fixco_custom/models/stock_picking.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index e4ed1b5..3610179 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -66,13 +66,44 @@ class StockPicking(models.Model): type_sku = fields.Selection([('single', 'Single SKU'), ('multi', 'Multi SKU')], string='Type SKU') list_product = fields.Char(string='List Product') + def create_invoices(self): + so_id = self.sale_id.id + if not so_id: + raise UserError(_("Gaada So nya!")) + + sale_orders = self.env['sale.order'].browse(so_id) + created_invoices = self.env['account.move'] + + for order in sale_orders: + invoice = order.with_context(default_invoice_origin=order.name)._create_invoices(final=True) + invoice.action_post() + created_invoices += invoice + + order.invoice_ids += invoice + + if created_invoices: + action = { + 'name': _('Created Invoice'), + 'type': 'ir.actions.act_window', + 'res_model': 'account.move', + 'view_mode': 'form', + 'res_id': created_invoices.id, + } + else: + action = {'type': 'ir.actions.act_window_close'} + + return action + def button_validate(self): origin = self.origin or '' if any(prefix in origin for prefix in ['PO/', 'SO/']) and not self.check_product_lines and not self.name.startswith('BU/INT'): raise UserError(_("Belum ada check product, gabisa validate")) + + res = super(StockPicking, self).button_validate() - - return super(StockPicking, self).button_validate() + if self.name.startswith('BU/OUT') and self.origin.startswith('SO/'): + self.create_invoices() + return res @api.depends('move_lines.origin_returned_move_id') |
