Skip to content

Commit 30162f6

Browse files
committed
[IMP] sale_order_action_invoice_create_hook: Add more options to the hook
1 parent bdc43c1 commit 30162f6

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

sale_order_action_invoice_create_hook/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Sale Order Action Invoice Create Hook",
66
"author": "Eficent, Odoo Community Association (OCA)",
7-
"version": "11.0.1.0.0",
7+
"version": "11.0.1.0.1",
88
"category": "Sale Workflow",
99
"website": "https://github.com/OCA/sale-workflow",
1010
"depends": [

sale_order_action_invoice_create_hook/hooks.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,29 @@ def new_action_invoice_create(self, grouped=False, final=False):
3939
new_lines = False
4040
# END HOOK
4141
for order in self:
42-
# START HOOK
43-
# Add more flexibility in grouping key fields
44-
# WAS: group_key = order.id if grouped
45-
# else (order.partner_invoice_id.id, order.currency_id.id)
46-
group_key = order.id if grouped else \
47-
self._get_invoice_group_key(order)
48-
# 'invoice' must be always instantiated respecting the old logic
49-
if group_key in invoices:
50-
invoice = invoices[group_key]
51-
# END HOOK
5242
for line in order.order_line.sorted(
5343
key=lambda l: l.qty_to_invoice < 0):
5444
if float_is_zero(line.qty_to_invoice,
5545
precision_digits=precision):
5646
continue
47+
# START HOOK
48+
# Allow to check if a line should not be invoiced
49+
if line._do_not_invoice():
50+
continue
51+
# END HOOK
52+
# START HOOK
53+
# Add more flexibility in grouping key fields
54+
# WAS: group_key = order.id if grouped
55+
# else (order.partner_invoice_id.id, order.currency_id.id)
56+
group_key = order.id if grouped else \
57+
self._get_invoice_group_line_key(line)
58+
# 'invoice' must be always instantiated
59+
# respecting the old logic
60+
if group_key in invoices:
61+
invoice = invoices[group_key]
62+
# END HOOK
5763
if group_key not in invoices:
58-
inv_data = order._prepare_invoice()
64+
inv_data = line._prepare_invoice()
5965
invoice = inv_obj.create(inv_data)
6066
references[invoice] = order
6167
invoices[group_key] = invoice

sale_order_action_invoice_create_hook/model/sale_order.py

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ class SaleOrder(models.Model):
1111
def _get_invoice_group_key(self, order):
1212
return (order.partner_invoice_id.id, order.currency_id.id)
1313

14+
@api.model
15+
def _get_invoice_group_line_key(self, line):
16+
return self._get_invoice_group_key(line.order_id)
17+
1418
@api.model
1519
def _get_draft_invoices(self, invoices, references):
1620
return invoices, references
21+
22+
23+
class SaleOrderLine(models.Model):
24+
_inherit = 'sale.order.line'
25+
26+
def _prepare_invoice(self):
27+
return self.order_id._prepare_invoice()
28+
29+
def _do_not_invoice(self):
30+
return False

0 commit comments

Comments
 (0)