diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-08 08:58:46 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-08 08:58:46 +0700 |
| commit | b858358ffbdd14c9b56ac96f035bddccae4d872d (patch) | |
| tree | 0058aeea123b8e2c29ab704f98806b227838dbbe /fixco_custom/models/account_move.py | |
| parent | 8f07d24c8362cb6a4d5ded8f94b75c5057a5b025 (diff) | |
skema bills and requisition
Diffstat (limited to 'fixco_custom/models/account_move.py')
| -rw-r--r-- | fixco_custom/models/account_move.py | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py index 0cdc22d..0a417cd 100644 --- a/fixco_custom/models/account_move.py +++ b/fixco_custom/models/account_move.py @@ -23,6 +23,14 @@ class AccountMove(models.Model): ('difaktur', 'Faktur Pajak')], string='Transaction Type' ) + purchase_vendor_bill_ids = fields.Many2many( + 'purchase.bill.union', + string='Auto-complete', + store=False, + readonly=True, + states={'draft': [('readonly', False)]}, + help="Auto-complete from multiple past bills / purchase orders.", + ) def action_post(self): @@ -30,4 +38,54 @@ class AccountMove(models.Model): for entry in self: entry.invoice_date = entry.picking_id.date_done - return res
\ No newline at end of file + return res + + @api.onchange('purchase_vendor_bill_ids', 'purchase_id') + def _onchange_purchase_auto_complete(self): + """ Load from either multiple old purchase orders or vendor bills. """ + + vendor_bills = self.purchase_vendor_bill_ids.mapped('vendor_bill_id') + purchase_orders = self.purchase_vendor_bill_ids.mapped('purchase_order_id') + + for bill in vendor_bills: + self.invoice_vendor_bill_id = bill + self._onchange_invoice_vendor_bill() + + for po in purchase_orders: + self.purchase_id = po + + invoice_vals = po.with_company(po.company_id)._prepare_invoice() + invoice_vals['currency_id'] = self.line_ids and self.currency_id or invoice_vals.get('currency_id') + invoice_vals.pop('ref', None) + self.update(invoice_vals) + + po_lines = po.order_line - self.line_ids.mapped('purchase_line_id') + new_lines = self.env['account.move.line'] + sequence = max(self.line_ids.mapped('sequence')) + 1 if self.line_ids else 10 + + for line in po_lines.filtered(lambda l: not l.display_type): + line_vals = line._prepare_account_move_line(self) + line_vals.update({'sequence': sequence}) + new_line = new_lines.new(line_vals) + sequence += 1 + new_line.account_id = new_line._get_computed_account() + new_line._onchange_price_subtotal() + new_lines += new_line + + new_lines._onchange_mark_recompute_taxes() + + # Compute invoice_origin + origins = set(self.line_ids.mapped('purchase_line_id.order_id.name')) + self.invoice_origin = ', '.join(origins) + + # Compute ref + refs = self._get_invoice_reference() + self.ref = ', '.join(refs) + + # Compute payment_reference + if len(refs) == 1: + self.payment_reference = refs[0] + + self.purchase_id = False + self.purchase_vendor_bill_ids = [(5, 0, 0)] # clear after use + self._onchange_currency() |
