From f0fdef1687cf29adb42fbb10512820088d8a9953 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Fri, 9 Jan 2026 14:45:09 +0700 Subject: CR Bills pahri --- fixco_custom/models/account_move.py | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'fixco_custom/models/account_move.py') diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py index e40e65f..df95f4e 100644 --- a/fixco_custom/models/account_move.py +++ b/fixco_custom/models/account_move.py @@ -47,6 +47,25 @@ class AccountMove(models.Model): compute="_compute_need_refund", help="Flag otomatis kalau invoice sudah paid dan picking terkait di-return." ) + # purchase_item_ids= fields.Many2many( + # 'purchase.order.line', + # string='Auto Complete (PO Item)', + # ) + + def action_open_po_item_wizard(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'name': 'Select PO Items', + 'res_model': 'purchase.order.line.wizard', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_move_id': self.id, + 'default_partner_id': self.partner_id.id, + } + } + def queue_job_cancel_bill(self): QueueJob = self.env['queue.job'] @@ -282,3 +301,46 @@ class AccountMove(models.Model): self.purchase_id = False self.purchase_vendor_bill_ids = [(5, 0, 0)] # clear after use self._onchange_currency() + +class PurchaseOrderLineWizard(models.TransientModel): + _name = 'purchase.order.line.wizard' + _description = 'PO Item Selector Wizard' + + move_id = fields.Many2one('account.move', required=True) + partner_id = fields.Many2one('res.partner') + + line_ids = fields.Many2many( + 'purchase.order.line', + string='PO Items', + ) + + def action_add_lines(self): + self.ensure_one() + move = self.move_id + + if move.state != 'draft': + raise UserError('Invoice harus draft') + + existing = move.invoice_line_ids.mapped('purchase_line_id') + + for po_line in self.line_ids: + if po_line in existing: + continue + + line = self.env['account.move.line'].with_context( + check_move_validity=False + ).new({ + 'move_id': move.id, + 'product_id': po_line.product_id.id, + }) + + # 🔑 trigger onchange resmi Odoo 14 + line._onchange_product_id() + + line.name = po_line.name + line.quantity = po_line.product_qty - po_line.qty_invoiced + line.price_unit = po_line.price_unit + line.tax_ids = po_line.taxes_id + line.purchase_line_id = po_line.id + + move.invoice_line_ids += line -- cgit v1.2.3