diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-07 17:12:10 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-07 17:12:10 +0700 |
| commit | ecbdec9343e56effbacb56d0060f7a6e9912f047 (patch) | |
| tree | aa80d251ee328c6e7baacbc2f9810deaa82e3d8b | |
| parent | e0f5ab6506c6314d93b378e8c5f0d5cd5a4f423c (diff) | |
push upload bills queue job
| -rwxr-xr-x | fixco_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | fixco_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | fixco_custom/models/purchase_order.py | 12 | ||||
| -rw-r--r-- | fixco_custom/models/purchase_order_multi_bills.py | 62 | ||||
| -rwxr-xr-x | fixco_custom/models/sale.py | 1 | ||||
| -rw-r--r-- | fixco_custom/models/upload_cancel_picking.py | 6 | ||||
| -rw-r--r-- | fixco_custom/models/upload_ginee.py | 1 | ||||
| -rwxr-xr-x | fixco_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | fixco_custom/views/purchase_order.xml | 7 | ||||
| -rw-r--r-- | fixco_custom/views/purchase_order_multi_bills.xml | 36 |
10 files changed, 128 insertions, 2 deletions
diff --git a/fixco_custom/__manifest__.py b/fixco_custom/__manifest__.py index 0543ec2..4925d69 100755 --- a/fixco_custom/__manifest__.py +++ b/fixco_custom/__manifest__.py @@ -50,6 +50,7 @@ 'views/wizard_purchase_pricelist.xml', 'views/upload_cancel_picking.xml', 'views/queue_job.xml', + 'views/purchase_order_multi_bills.xml', ], 'demo': [], 'css': [], diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py index c13c9a3..0068d32 100755 --- a/fixco_custom/models/__init__.py +++ b/fixco_custom/models/__init__.py @@ -38,3 +38,4 @@ from . import account_move_reversal from . import upload_cancel_picking from . import product_supplierinfo from . import queue_job +from . import purchase_order_multi_bills
\ No newline at end of file diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index 43fe8f6..c745fbe 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -58,6 +58,18 @@ class PurchaseOrder(models.Model): soo_tax = fields.Float('SOO Tax', copy=False) discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product', copy=False, default=0.0) + def open_form_multi_create_bills(self): + return { + 'name': _('Create Bills'), + 'type': 'ir.actions.act_window', + 'res_model': 'purchase.order.multi_bills', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'po_ids': self.ids, + } + } + def _get_fixco_token(self, source='auto'): ICP = self.env['ir.config_parameter'].sudo() TokenLog = self.env['token.log'].sudo() 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 diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index 8b04538..cd5f68f 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -25,6 +25,7 @@ class SaleOrder(models.Model): # Create invoice for this SO only invoice = order.with_context(default_invoice_origin=order.name)._create_invoices(final=True) invoice.action_post() + invoice.invoice_date = invoice.picking_id.date_done created_invoices += invoice # Link the invoice to the SO diff --git a/fixco_custom/models/upload_cancel_picking.py b/fixco_custom/models/upload_cancel_picking.py index b4038bf..54a94d5 100644 --- a/fixco_custom/models/upload_cancel_picking.py +++ b/fixco_custom/models/upload_cancel_picking.py @@ -144,9 +144,13 @@ class UploadCancelPicking(models.Model): } def action_cancel_picking(self): + self.date_upload = datetime.utcnow() for line in self.picking_lines: + queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'cancel_picking')], limit=1) + if queue_job: + continue self.env['queue.job'].create({ - 'name': f'Cancel Picking {line.name}', + 'name': f'Cancel Picking {line.picking_id.name}', 'model_name': 'upload.cancel.picking.line', 'method_name': 'cancel_picking', 'res_id': line.id, diff --git a/fixco_custom/models/upload_ginee.py b/fixco_custom/models/upload_ginee.py index 4341269..282bf74 100644 --- a/fixco_custom/models/upload_ginee.py +++ b/fixco_custom/models/upload_ginee.py @@ -167,6 +167,7 @@ class UploadGinee(models.Model): # self.ginee_lines.create_so_and_detail_order() def action_get_order_id_and_create_detail_order(self): + self.date_upload = datetime.utcnow() for line in self.ginee_lines: queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'get_order_id_and_create_detail_order')], limit=1) if queue_job: diff --git a/fixco_custom/security/ir.model.access.csv b/fixco_custom/security/ir.model.access.csv index 817595b..a0ac394 100755 --- a/fixco_custom/security/ir.model.access.csv +++ b/fixco_custom/security/ir.model.access.csv @@ -44,4 +44,5 @@ access_stock_return_picking,stock.return.picking,model_stock_return_picking,,1,1 access_stock_return_picking_line,stock.return.picking.line,model_stock_return_picking_line,,1,1,1,1 access_upload_cancel_picking,access.upload.cancel.picking,model_upload_cancel_picking,,1,1,1,1 access_upload_cancel_picking_line,access.upload.cancel.picking.line,model_upload_cancel_picking_line,,1,1,1,1 -access_queue_job,access.queue.job,model_queue_job,,1,1,1,1
\ No newline at end of file +access_queue_job,access.queue.job,model_queue_job,,1,1,1,1 +access_purchase_order_multi_bills,access.purchase.order.multi_bills,model_purchase_order_multi_bills,,1,1,1,1
\ No newline at end of file diff --git a/fixco_custom/views/purchase_order.xml b/fixco_custom/views/purchase_order.xml index d5e612c..128224d 100644 --- a/fixco_custom/views/purchase_order.xml +++ b/fixco_custom/views/purchase_order.xml @@ -61,5 +61,12 @@ </field> </field> </record> + <record id="purchase_order_multi_create_bills_ir_actions_server" model="ir.actions.server"> + <field name="name">Multi Bills</field> + <field name="model_id" ref="purchase.model_purchase_order"/> + <field name="binding_model_id" ref="purchase.model_purchase_order"/> + <field name="state">code</field> + <field name="code">action = records.open_form_multi_create_bills()</field> + </record> </data> </odoo> diff --git a/fixco_custom/views/purchase_order_multi_bills.xml b/fixco_custom/views/purchase_order_multi_bills.xml new file mode 100644 index 0000000..dbcbc4a --- /dev/null +++ b/fixco_custom/views/purchase_order_multi_bills.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <data> + <record id="view_purchase_order_multi_create_bills_form" model="ir.ui.view"> + <field name="name">Purchase Order Multi Create Bills</field> + <field name="model">purchase.order.multi_bills</field> + <field name="arch" type="xml"> + <form string="Create Bills"> + <sheet> + <div class="oe_title"> + <h2>Create Bills for Selected Sales Orders</h2> + </div> + <div class="alert alert-info"> + <p>This will create Bills for all selected sales orders.</p> + <p>Total orders selected: <strong><span t-esc="len(context.get('so_ids', []))"/></strong></p> + </div> + </sheet> + <footer> + <button name="queue_job" string="Create Bills" type="object" + class="btn-primary" default_focus="1"/> + <button string="Cancel" class="btn-secondary" special="cancel"/> + </footer> + </form> + </field> + </record> + + <record id="action_purchase_order_multi_bills" model="ir.actions.act_window"> + <field name="name">Create Bills</field> + <field name="res_model">purchase.order.multi_bills</field> + <field name="type">ir.actions.act_window</field> + <field name="view_mode">form</field> + <field name="view_id" ref="view_purchase_order_multi_create_bills_form"/> + <field name="target">new</field> + </record> + </data> +</odoo>
\ No newline at end of file |
