summaryrefslogtreecommitdiff
path: root/fixco_custom/models/sale.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-05-31 11:17:59 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-05-31 11:17:59 +0700
commit610eb5a98791cf97c730723b86b461e431c0891f (patch)
tree2236a5df19429d4fc050eca744cbb65337a3b9e1 /fixco_custom/models/sale.py
parent479924f6dbabb55f777194f80cf278a909452e95 (diff)
add invoice marketplace when create invoice
Diffstat (limited to 'fixco_custom/models/sale.py')
-rwxr-xr-xfixco_custom/models/sale.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py
index 24ac70a..8269fce 100755
--- a/fixco_custom/models/sale.py
+++ b/fixco_custom/models/sale.py
@@ -16,6 +16,43 @@ class SaleOrder(models.Model):
# }
# return action
+ def _prepare_invoice(self):
+ """
+ Prepare the dict of values to create the new invoice for a sales order. This method may be
+ overridden to implement custom invoice generation (making sure to call super() to establish
+ a clean extension chain).
+ """
+ self.ensure_one()
+ journal = self.env['account.move'].with_context(default_move_type='out_invoice')._get_default_journal()
+ if not journal:
+ raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (self.company_id.name, self.company_id.id))
+
+ invoice_vals = {
+ 'ref': self.client_order_ref or '',
+ 'move_type': 'out_invoice',
+ 'narration': self.note,
+ 'invoice_marketplace': self.invoice_mp,
+ 'currency_id': self.pricelist_id.currency_id.id,
+ 'campaign_id': self.campaign_id.id,
+ 'medium_id': self.medium_id.id,
+ 'source_id': self.source_id.id,
+ 'user_id': self.user_id.id,
+ 'invoice_user_id': self.user_id.id,
+ 'team_id': self.team_id.id,
+ 'partner_id': self.partner_invoice_id.id,
+ 'partner_shipping_id': self.partner_shipping_id.id,
+ 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(self.partner_invoice_id.id)).id,
+ 'partner_bank_id': self.company_id.partner_id.bank_ids.filtered(lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id,
+ 'journal_id': journal.id, # company comes from the journal
+ 'invoice_origin': self.name,
+ 'invoice_payment_term_id': self.payment_term_id.id,
+ 'payment_reference': self.reference,
+ 'transaction_ids': [(6, 0, self.transaction_ids.ids)],
+ 'invoice_line_ids': [],
+ 'company_id': self.company_id.id,
+ }
+ return invoice_vals
+
def open_form_multi_create_invoices(self):
return {
'name': _('Create Invoices'),