summaryrefslogtreecommitdiff
path: root/fixco_custom/models/purchase_order_multi_bills.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2026-01-07 17:12:10 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2026-01-07 17:12:10 +0700
commitecbdec9343e56effbacb56d0060f7a6e9912f047 (patch)
treeaa80d251ee328c6e7baacbc2f9810deaa82e3d8b /fixco_custom/models/purchase_order_multi_bills.py
parente0f5ab6506c6314d93b378e8c5f0d5cd5a4f423c (diff)
push upload bills queue job
Diffstat (limited to 'fixco_custom/models/purchase_order_multi_bills.py')
-rw-r--r--fixco_custom/models/purchase_order_multi_bills.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/fixco_custom/models/purchase_order_multi_bills.py b/fixco_custom/models/purchase_order_multi_bills.py
new file mode 100644
index 0000000..d9e3c0d
--- /dev/null
+++ b/fixco_custom/models/purchase_order_multi_bills.py
@@ -0,0 +1,62 @@
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError
+
+class PurchaeOrderMultiBills(models.TransientModel):
+ _name = 'purchase.order.multi_bills'
+ _description = 'Create bills for Multiple purchases Orders'
+
+ def queue_job(self):
+ po_ids = self._context.get('po_ids', [])
+ purchase_orders = self.env['purchase.order'].browse(po_ids)
+ for purchase in purchase_orders:
+ queue_job = self.env['queue.job'].search([('res_id', '=', purchase.id), ('method_name', '=', 'create_bills')], limit=1)
+ if queue_job:
+ continue
+ self.env['queue.job'].create({
+ 'name': f'Create Bills {purchase.name}',
+ 'model_name': 'purchase.order',
+ 'method_name': 'action_create_invoice',
+ 'res_id': purchase.id,
+ })
+
+ # def create_bills(self):
+ # # Get SO IDs from context
+ # po_ids = self._context.get('po_ids', [])
+ # if not po_ids:
+ # raise UserError(_("No purchases orders selected!"))
+
+ # # Browse all selected purchases orders
+ # purchase_orders = self.env['purchase.order'].browse(po_ids)
+ # created_bills = self.env['account.move']
+
+ # # Create one invoice per SO (even if partner is the same)
+ # for order in purchase_orders:
+ # # Create invoice for this SO only
+ # invoice = order.with_context(default_invoice_origin=order.name)._create_bills(final=True)
+ # invoice.action_post()
+ # created_bills += invoice
+
+ # # Link the invoice to the SO
+ # order.invoice_ids += invoice
+
+ # # Return action to view created bills
+ # if len(created_bills) > 1:
+ # action = {
+ # 'name': _('Created bills'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'tree,form',
+ # 'domain': [('id', 'in', created_bills.ids)],
+ # }
+ # elif created_bills:
+ # action = {
+ # 'name': _('Created Invoice'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'form',
+ # 'res_id': created_bills.id,
+ # }
+ # else:
+ # action = {'type': 'ir.actions.act_window_close'}
+
+ # return action \ No newline at end of file