Skip to content

Commit

Permalink
[IMP] sale_line_refund_to_invoice_qty: Initialize value with sql default
Browse files Browse the repository at this point in the history
As Odoo initializes default values on records by an update on all existing ones,
this can take a great amount of time. Instead, use sql default value at column
creation.
  • Loading branch information
rousseldenis committed Feb 4, 2025
1 parent b514db4 commit 9b1c032
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions sale_line_refund_to_invoice_qty/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Contributors

* Jordi Masvidal <[email protected]>
* Lois Rilo <[email protected]>
* Denis Roussel <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion sale_line_refund_to_invoice_qty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from .hooks import pre_init_hook
from . import models
from . import wizards
4 changes: 4 additions & 0 deletions sale_line_refund_to_invoice_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
"views/sale_order_views.xml",
"wizards/account_move_reversal_view.xml",
],
"external_dependencies": {
"python": ["openupgradelib"],
},
"pre_init_hook": "pre_init_hook",
}
28 changes: 28 additions & 0 deletions sale_line_refund_to_invoice_qty/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade

from odoo import SUPERUSER_ID, api


def pre_init_hook(cr):
"""
Initialize 'sale_qty_to_reinvoice' field with sql default value
for performances reasons as Odoo does it with an update instead.
"""
if openupgrade.column_exists(cr, "account_move_line", "sale_qty_to_reinvoice"):
return

Check warning on line 14 in sale_line_refund_to_invoice_qty/hooks.py

View check run for this annotation

Codecov / codecov/patch

sale_line_refund_to_invoice_qty/hooks.py#L14

Added line #L14 was not covered by tests

env = api.Environment(cr, SUPERUSER_ID, {})
field_spec = [
(
"sale_qty_to_reinvoice",
"account.move.line",
"account_move_line",
"boolean",
"boolean",
"sale_line_refund_to_invoice_qty",
True,
)
]
openupgrade.add_fields(env, field_spec=field_spec)
1 change: 1 addition & 0 deletions sale_line_refund_to_invoice_qty/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Jordi Masvidal <[email protected]>
* Lois Rilo <[email protected]>
* Denis Roussel <[email protected]>
13 changes: 8 additions & 5 deletions sale_line_refund_to_invoice_qty/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -417,12 +417,15 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Jordi Masvidal &lt;<a class="reference external" href="mailto:jordi.masvidal&#64;forgeflow.com">jordi.masvidal&#64;forgeflow.com</a>&gt;</li>
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<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>
Expand Down

0 comments on commit 9b1c032

Please sign in to comment.