summaryrefslogtreecommitdiff
path: root/fixco_custom/models/stock_picking.py
diff options
context:
space:
mode:
Diffstat (limited to 'fixco_custom/models/stock_picking.py')
-rwxr-xr-xfixco_custom/models/stock_picking.py35
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')