diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-23 11:08:47 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-23 11:08:47 +0700 |
| commit | 24c863b30575eca63efe245b4b25c92e1ce3f4d6 (patch) | |
| tree | 61ade1c16d67bcb4bb53512a1350e14c933f342e /fixco_custom/models/stock_picking.py | |
| parent | 175b10a298185a724b7c0f8d0d25beec38b4f0e1 (diff) | |
| parent | aeeecacfe7b10ebbdefe5284f98e9e9f37c1b8d1 (diff) | |
Merge branch 'main' of https://bitbucket.org/altafixco/fixco-addons
merge
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 5c83ac8..ffa5f4a 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') |
