Skip to content

Commit

Permalink
fix stock move
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaniszewska-dev committed Jul 11, 2022
1 parent 2f8095d commit c58103e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
3 changes: 0 additions & 3 deletions stock_picking_invoice_link/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class AccountMove(models.Model):
string="Related Pickings",
store=True,
compute="_compute_picking_ids",
relation="account_invoice_stock_picking_rel",
column1="account_invoice_id",
column2="stock_picking_id",
help="Related pickings "
"(only when the invoice has been generated from a sale order).",
)
Expand Down
6 changes: 3 additions & 3 deletions stock_picking_invoice_link/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class SaleOrderLine(models.Model):
def get_stock_moves_link_invoice(self):
return self.mapped("move_ids")._filter_for_invoice_link()

def _prepare_invoice_line(self, qty):
vals = super()._prepare_invoice_line(qty)
def _prepare_invoice_line(self, **optional_values):
vals = super()._prepare_invoice_line(**optional_values)
stock_moves = self.get_stock_moves_link_invoice()
# Invoice returned moves marked as to_refund
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
if float_compare(qty, 0.0, precision_digits=precision) < 0:
if float_compare(self.product_uom_qty, 0.0, precision_digits=precision) < 0:
stock_moves = stock_moves.filtered(
lambda m: m.to_refund and not m.invoice_line_ids
)
Expand Down
6 changes: 3 additions & 3 deletions stock_picking_invoice_link/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _filter_for_invoice_link(self):
and not (
any(
inv.state != "cancel"
for inv in x.invoice_line_ids.mapped("invoice_id")
for inv in x.invoice_line_ids.mapped("move_id")
)
)
and not x.scrapped
Expand All @@ -54,8 +54,8 @@ def _filter_for_invoice_link(self):
)
)

def _action_done(self):
res = super()._action_done()
def _action_done(self, cancel_backorder=False):
res = super()._action_done(cancel_backorder)
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
Expand Down
5 changes: 1 addition & 4 deletions stock_picking_invoice_link/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ class StockPicking(models.Model):
_inherit = "stock.picking"

invoice_ids = fields.Many2many(
comodel_name="account.invoice",
comodel_name="account.move",
copy=False,
string="Invoices",
readonly=True,
relation="account_invoice_stock_picking_rel",
column1="stock_picking_id",
column2="account_invoice_id",
)

def action_view_invoice(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ def setUpClass(cls, chart_template_ref=None):

def test_00_sale_stock_invoice_link(self):
pick_obj = self.env["stock.picking"]
inv_obj = self.env["account.invoice"]
# invoice on order
inv_id = self.so.action_invoice_create()
inv_0 = inv_obj.browse(inv_id)
inv_0 = self.so._create_invoices()
# deliver partially
self.assertEqual(
self.so.invoice_status,
Expand Down Expand Up @@ -184,7 +182,7 @@ def test_00_sale_stock_invoice_link(self):
# Invoice view
result = pick_1.action_view_invoice()
self.assertEqual(result["views"][0][1], "tree")
self.assertEqual(pick_1.invoice_ids, inv_1 | inv_0)
self.assertEqual(pick_1.invoice_ids.ids, (inv_0 | inv_1).ids)
# Mock multiple invoices linked to a picking
inv_3 = inv_1.copy()
inv_3.picking_ids |= pick_1
Expand Down
2 changes: 1 addition & 1 deletion stock_picking_invoice_link/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Copyright 2013-2014 Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<record id="invoice_form" model="ir.ui.view">
<field name="name">related.pickings.account.invoice.form</field>
<field name="name">related.pickings.account.move.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
Expand Down

0 comments on commit c58103e

Please sign in to comment.