diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-07 18:05:30 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-07 18:05:30 +0700 |
| commit | 23b2c540774c064a69c77ed3de29d9f99ffae904 (patch) | |
| tree | b0d1bc2f0be8bee2db2dc0fa5655cd0ec4a9b388 | |
| parent | ecbdec9343e56effbacb56d0060f7a6e9912f047 (diff) | |
push
| -rw-r--r-- | fixco_custom/models/purchase_order.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index c745fbe..ef80112 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -58,6 +58,41 @@ 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'), |
