Skip to content

Commit

Permalink
stock_picking_invoice_link: Support invoiced on ordered qties
Browse files Browse the repository at this point in the history
  • Loading branch information
grindtildeath authored and ajaniszewska-dev committed Jun 1, 2022
1 parent 257acd8 commit d33bbf9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
25 changes: 25 additions & 0 deletions stock_picking_invoice_link/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_compare


class StockMove(models.Model):
Expand Down Expand Up @@ -46,3 +47,27 @@ def _filter_for_invoice_link(self):
x.to_refund))
)
)

def _action_done(self):
res = super()._action_done()
precision = self.env['decimal.precision'].precision_get(
'Product Unit of Measure'
)
moves = self._filter_for_invoice_link()
# Add extra filtering on products with invoice_policy = delivery as
# the link was already set at invoice creation
for move in moves.filtered(
lambda m: m.product_id.invoice_policy != "delivery"
):
if float_compare(
move.sale_line_id.qty_to_invoice, 0.0, precision_digits=precision
) < 0 and (not move.to_refund or move.invoice_line_ids):
continue
move.write(
{
"invoice_line_ids": [
(4, inv_line.id) for inv_line in move.sale_line_id.invoice_lines
]
}
)
return res
3 changes: 0 additions & 3 deletions stock_picking_invoice_link/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ invoices relate to. You only have the quantity.

This module is also useful if you want to present data on the invoice report
grouped by deliveries.

Note that the links are only for products with an invoicing policy set on
delivery.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def setUpClass(cls, chart_template_ref=None):
def test_00_sale_stock_invoice_link(self):
pick_obj = self.env["stock.picking"]
# invoice on order
self.so._create_invoices()
inv_id = self.so.action_invoice_create()
inv_0 = inv_obj.browse(inv_id)
# deliver partially
self.assertEqual(
self.so.invoice_status,
Expand Down Expand Up @@ -144,10 +145,24 @@ def test_00_sale_stock_invoice_link(self):
)
# Check links
self.assertEqual(
inv_1.picking_ids,
pick_1,
"Invoice 1 must link to only First Partial Delivery",
inv_0.picking_ids, pick_1 | pick_2,
"Invoice 0 must be linked to all the deliveries"
)
self.assertEqual(
inv_0.invoice_line_ids.mapped('move_line_ids'),
pick_1.move_lines.filtered(
lambda x: x.product_id.invoice_policy == "order"
) |
pick_2.move_lines.filtered(
lambda x: x.product_id.invoice_policy == "order"
)
,
"Invoice 0 lines must be link to all delivery lines for "
"ordered quantities"
)
self.assertEqual(
inv_1.picking_ids, pick_1,
"Invoice 1 must link to only First Partial Delivery")
self.assertEqual(
inv_1.invoice_line_ids.mapped("move_line_ids"),
pick_1.move_lines.filtered(
Expand All @@ -167,8 +182,8 @@ def test_00_sale_stock_invoice_link(self):
)
# Invoice view
result = pick_1.action_view_invoice()
self.assertEqual(result["views"][0][1], "form")
self.assertEqual(result["res_id"], inv_1.id)
self.assertEqual(result['views'][0][1], 'tree')
self.assertEqual(pick_1.invoice_ids, inv_1 | inv_0)
# Mock multiple invoices linked to a picking
inv_3 = inv_1.copy()
inv_3.picking_ids |= pick_1
Expand Down

0 comments on commit d33bbf9

Please sign in to comment.