diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2026-01-14 03:32:56 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2026-01-14 03:32:56 +0000 |
| commit | d7cafd5a4db30b08dceabf8999a0903b6871368d (patch) | |
| tree | a464c57c47fa80101933faaec0b7458cba605d8a /fixco_custom/models | |
| parent | 7eb25a9ae2ef304503749f8023b8d2f5e2a2e58f (diff) | |
| parent | c4a4653e4065789a9c1baa97e91709ea52a6131e (diff) | |
Merged in bills_add_item_po (pull request #3)
Bills add item po
Diffstat (limited to 'fixco_custom/models')
| -rw-r--r-- | fixco_custom/models/account_move.py | 61 | ||||
| -rw-r--r-- | fixco_custom/models/purchase_order_line.py | 7 |
2 files changed, 66 insertions, 2 deletions
diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py index f6fd742..a0de6bb 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, + } + } + approval_refund = fields.Selection( [('approved', 'Approved'), ('rejected', 'Rejected'), @@ -266,8 +285,6 @@ class AccountMove(models.Model): if entry.move_type == 'out_invoice': if entry.picking_id: entry.invoice_date = entry.picking_id.date_done - - return res @api.onchange('purchase_vendor_bill_ids', 'purchase_id') @@ -320,3 +337,43 @@ 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') + + + for po_line in self.line_ids: + + line = self.env['account.move.line'].with_context( + check_move_validity=False + ).new({ + 'move_id': move.id, + 'product_id': po_line.product_id.id, + }) + + line._onchange_product_id() + + line.name = po_line.name + # 🔹 Hanya qty yang belum di-invoice + 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 diff --git a/fixco_custom/models/purchase_order_line.py b/fixco_custom/models/purchase_order_line.py index 53a5eba..bdd729c 100644 --- a/fixco_custom/models/purchase_order_line.py +++ b/fixco_custom/models/purchase_order_line.py @@ -38,6 +38,13 @@ class PurchaseOrderLine(models.Model): original_price_subtotal = fields.Float(string='Original Subtotal', readonly=True) description = fields.Text(string='Description', readonly=True, copy=False) docstatus_altama = fields.Text(string='Status Altama', readonly=True, copy=False) + bill_remain = fields.Float(string='Bill Remain', readonly=True, copy=False, tracking=True, compute='_compute_bill_remain') + + @api.depends('qty_invoiced', 'product_qty') + def _compute_bill_remain(self): + for line in self: + line.bill_remain = line.product_qty - line.qty_invoiced + @api.constrains('product_id', 'price_unit', 'product_qty') def _store_original_price(self): |
