1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class SaleOrder(models.Model):
_inherit = "sale.order"
carrier = fields.Char(string='Shipping Method')
invoice_mp = fields.Char(string='Invoice Marketplace')
order_reference = fields.Char(string='Order Reference')
address = fields.Char('Address')
note_by_buyer = fields.Char('Note By Buyer')
# def open_form_multi_create_invoices(self):
# action = self.env['ir.actions.act_window']._for_xml_id('fixco_custom.action_sale_order_multi_invoices')
# action['context'] = {
# 'so_ids': [x.id for x in self]
# }
# 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))
done_pickings = self.picking_ids.filtered(lambda p: p.state == 'done').sorted(key='create_date')
invoice_vals = {
'ref': self.client_order_ref or '',
'move_type': 'out_invoice',
'narration': self.note,
'invoice_marketplace': self.invoice_mp,
'address': self.address,
'sale_id': self.id,
'picking_id': done_pickings[0] if done_pickings else False,
'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'),
'type': 'ir.actions.act_window',
'res_model': 'sale.order.multi_invoices',
'view_mode': 'form',
'target': 'new',
'context': {
'so_ids': self.ids,
}
}
|