diff options
| -rwxr-xr-x | fixco_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | fixco_custom/models/__init__.py | 1 | ||||
| -rwxr-xr-x | fixco_custom/models/detail_order.py | 2 | ||||
| -rw-r--r-- | fixco_custom/models/purchase_order.py | 47 | ||||
| -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/shipment_group.py | 2 | ||||
| -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 |
12 files changed, 165 insertions, 4 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/detail_order.py b/fixco_custom/models/detail_order.py index 847c41e..b3e10a2 100755 --- a/fixco_custom/models/detail_order.py +++ b/fixco_custom/models/detail_order.py @@ -370,7 +370,7 @@ class DetailOrder(models.Model): sale_order.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', []) sale_order.action_cancel() - self.execute_status = 'cancelled_so_created' + self.execute_status = 'cancelled_so' return diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index 43fe8f6..ef80112 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -58,6 +58,53 @@ 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 _prepare_invoice(self): + """Prepare the dict of values to create the new invoice for a purchase order. + """ + self.ensure_one() + move_type = self._context.get('default_move_type', 'in_invoice') + journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal() + if not journal: + raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) + + partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice'] + partner_bank_id = self.partner_id.commercial_partner_id.bank_ids.filtered_domain(['|', ('company_id', '=', False), ('company_id', '=', self.company_id.id)])[:1] + invoice_vals = { + 'ref': self.partner_ref or '', + 'move_type': move_type, + 'invoice_date': datetime.utcnow(), + 'narration': self.notes, + 'currency_id': self.currency_id.id, + 'invoice_user_id': self.user_id and self.user_id.id or self.env.user.id, + 'partner_id': partner_invoice_id, + 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(partner_invoice_id)).id, + 'payment_reference': self.partner_ref or '', + 'partner_bank_id': partner_bank_id.id, + 'invoice_origin': self.name, + 'invoice_payment_term_id': self.payment_term_id.id, + 'invoice_line_ids': [], + 'company_id': self.company_id.id, + } + return invoice_vals + + @api.constrains('invoice_ids') + def _auto_action_post_bills(self): + for bill in self.invoice_ids: + if bill.state == 'draft': + bill.action_post() + + 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/shipment_group.py b/fixco_custom/models/shipment_group.py index 2e2dffa..4c4af4a 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -215,7 +215,7 @@ class ShipmentGroup(models.Model): return for item in contents: - order_no = item.get('orderNumber') + order_no = item.get('externalOrderId') order_status = item.get('orderStatus') picking_line = order_map.get(order_no) 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 |
