Skip to content

Commit

Permalink
[MIG] stock_picking_invoice_link: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyht27 authored and CarlosRoca13 committed Dec 2, 2022
1 parent cbb682c commit c332869
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 32 deletions.
8 changes: 4 additions & 4 deletions stock_picking_invoice_link/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Stock Picking Invoice Link
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_invoice_link
:target: https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_invoice_link
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_picking_invoice_link
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-stock_picking_invoice_link
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/154/14.0
:target: https://runbot.odoo-community.org/runbot/154/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -119,6 +119,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_invoice_link>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_invoice_link>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion stock_picking_invoice_link/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{
"name": "Stock Picking Invoice Link",
"version": "14.0.1.0.1",
"version": "15.0.1.0.0",
"category": "Warehouse Management",
"summary": "Adds link between pickings and invoices",
"author": "Agile Business Group, "
Expand Down
32 changes: 26 additions & 6 deletions stock_picking_invoice_link/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class AccountMove(models.Model):
string="Related Pickings",
store=True,
compute="_compute_picking_ids",
help="Related pickings "
"(only when the invoice has been generated from a sale order).",
help="Related pickings (only when the invoice has been generated from a sale order).",
)

delivery_count = fields.Integer(
string="Delivery Orders", compute="_compute_picking_ids", store=True
)

@api.depends("invoice_line_ids", "invoice_line_ids.move_line_ids")
Expand All @@ -26,6 +29,7 @@ def _compute_picking_ids(self):
invoice.picking_ids = invoice.mapped(
"invoice_line_ids.move_line_ids.picking_id"
)
invoice.delivery_count = len(invoice.picking_ids)

def action_show_picking(self):
"""This function returns an action that display existing pickings
Expand All @@ -35,8 +39,9 @@ def action_show_picking(self):
"""
self.ensure_one()
form_view_name = "stock.view_picking_form"
action = self.env.ref("stock.action_picking_tree_all").sudo()
result = action.read()[0]
result = self.env["ir.actions.act_window"]._for_xml_id(
"stock.action_picking_tree_all"
)
if len(self.picking_ids) > 1:
result["domain"] = "[('id', 'in', %s)]" % self.picking_ids.ids
else:
Expand All @@ -45,6 +50,20 @@ def action_show_picking(self):
result["res_id"] = self.picking_ids.id
return result

def _reverse_move_vals(self, default_values, cancel=True):
move_vals = super()._reverse_move_vals(default_values, cancel=cancel)
# Invoice returned moves marked as to_refund
for line_command in move_vals.get("line_ids", []):
line_vals = line_command[2]
product_id = line_vals.get("product_id", False)
if product_id:
stock_moves = self.line_ids.filtered(
lambda l: l.product_id.id == product_id
).mapped("move_line_ids")
if stock_moves:
line_vals["move_line_ids"] = [(4, m.id) for m in stock_moves]
return move_vals


class AccountMoveLine(models.Model):
_inherit = "account.move.line"
Expand All @@ -56,6 +75,7 @@ class AccountMoveLine(models.Model):
column2="move_id",
string="Related Stock Moves",
readonly=True,
help="Related stock moves "
"(only when the invoice has been generated from a sale order).",
copy=False,
help="Related stock moves (only when the invoice has been"
" generated from a sale order).",
)
15 changes: 12 additions & 3 deletions stock_picking_invoice_link/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright 2017 Jacques-Etienne Baudoux <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
from odoo import api, fields, models


class StockPicking(models.Model):
Expand All @@ -13,6 +13,9 @@ class StockPicking(models.Model):
invoice_ids = fields.Many2many(
comodel_name="account.move", copy=False, string="Invoices", readonly=True
)
invoice_count = fields.Integer(
string="Invoices Orders", compute="_compute_invoice_count"
)

def action_view_invoice(self):
"""This function returns an action that display existing invoices
Expand All @@ -22,12 +25,18 @@ def action_view_invoice(self):
"""
self.ensure_one()
form_view_name = "account.view_move_form"
action = self.env.ref("account.action_move_out_invoice_type").sudo()
result = action.read()[0]
result = self.env["ir.actions.act_window"]._for_xml_id(
"account.action_move_out_invoice_type"
)
if len(self.invoice_ids) > 1:
result["domain"] = "[('id', 'in', %s)]" % self.invoice_ids.ids
else:
form_view = self.env.ref(form_view_name)
result["views"] = [(form_view.id, "form")]
result["res_id"] = self.invoice_ids.id
return result

@api.depends("invoice_ids")
def _compute_invoice_count(self):
for order in self:
order.invoice_count = len(order.invoice_ids)
1 change: 1 addition & 0 deletions stock_picking_invoice_link/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
* Jacques-Etienne Baudoux <[email protected]>
* Aitor Bouzas Naveira <[email protected]>
* Carlos Lopez Mite <[email protected]>
* Joel Matías Zilli <[email protected]>
4 changes: 2 additions & 2 deletions stock_picking_invoice_link/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Stock Picking Invoice Link</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_invoice_link"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_picking_invoice_link"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/154/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_invoice_link"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-stock_picking_invoice_link"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/154/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds a link between pickings and invoices as well as on the lines.
Invoices are generated from sales orders. With this module, you can find back
which deliveries an invoice relates to.</p>
Expand Down Expand Up @@ -460,7 +460,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_picking_invoice_link">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_invoice_link">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright 2017 Jacques-Etienne Baudoux <[email protected]>
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests import Form, tagged

from odoo.addons.sale.tests.common import TestSaleCommon


@tagged("post_install", "-at_install")
class TestStockPickingInvoiceLink(TestSaleCommon):
@classmethod
def _update_product_qty(cls, product):
Expand Down Expand Up @@ -255,7 +255,13 @@ def test_invoice_refund(self):
wiz_invoice_refund = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=inv.ids)
.create({"refund_method": "modify", "reason": "test"})
.create(
{
"refund_method": "modify",
"reason": "test",
"journal_id": inv.journal_id.id,
}
)
)
wiz_invoice_refund.reverse_moves()
new_invoice = self.so.invoice_ids.filtered(
Expand Down Expand Up @@ -288,7 +294,13 @@ def test_invoice_refund_invoice(self):
wiz_invoice_refund = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=inv.ids)
.create({"refund_method": "cancel", "reason": "test"})
.create(
{
"refund_method": "cancel",
"reason": "test",
"journal_id": inv.journal_id.id,
}
)
)
wiz_invoice_refund.reverse_moves()
# Create invoice again
Expand All @@ -306,7 +318,7 @@ def test_partial_invoice_full_link(self):
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1.action_done()
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
with Form(inv) as move_form:
Expand All @@ -324,7 +336,7 @@ def test_return_and_invoice_refund(self):
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1.action_done()
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
inv_line_prod_del = inv.invoice_line_ids.filtered(
Expand Down
6 changes: 3 additions & 3 deletions stock_picking_invoice_link/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<div name="button_box" position="inside">
<field name="picking_ids" invisible="1" />
<button
type="object"
name="action_show_picking"
class="oe_stat_button"
icon="fa-truck"
type="object"
attrs="{'invisible': [('picking_ids', '=', [])]}"
string="Pickings"
attrs="{'invisible': [('delivery_count', '=', 0)]}"
>
<field name="delivery_count" widget="statinfo" string="Delivery" />
</button>
</div>
<xpath expr="//field[@name='invoice_line_ids']//tree" position="inside">
Expand Down
6 changes: 3 additions & 3 deletions stock_picking_invoice_link/views/stock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<div name="button_box" position="inside">
<field name="invoice_ids" invisible="1" />
<button
type="object"
name="action_view_invoice"
class="oe_stat_button"
icon="fa-pencil-square-o"
type="object"
attrs="{'invisible': [('invoice_ids', '=', [])]}"
string="Invoices"
attrs="{'invisible': [('invoice_count', '=', 0)]}"
>
<field name="invoice_count" widget="statinfo" string="Invoice" />
</button>
</div>
</field>
Expand Down
17 changes: 13 additions & 4 deletions stock_picking_invoice_link/wizards/account_move_reversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ def reverse_moves(self):
moves = self.env["account.move"].browse(action["res_id"])
else:
moves = self.env["account.move"].search(action["domain"])
for line in moves.mapped("invoice_line_ids"):
reverse_moves = line.move_line_ids.mapped("returned_move_ids")
if reverse_moves:
line.move_line_ids = reverse_moves
if self.refund_method == "modify":
origin_moves = self.move_ids
for line in origin_moves.mapped("invoice_line_ids"):
reverse_moves = line.move_line_ids.mapped("returned_move_ids")
if reverse_moves:
moves.mapped("invoice_line_ids").filtered(
lambda m: m.product_id == line.product_id
).move_line_ids = reverse_moves
else:
for line in moves.mapped("invoice_line_ids"):
reverse_moves = line.move_line_ids.mapped("returned_move_ids")
if reverse_moves:
line.move_line_ids = reverse_moves
return action

0 comments on commit c332869

Please sign in to comment.