Skip to content

Commit

Permalink
[MIG] purchase_open_qty: Migrate to version 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 committed Jan 12, 2024
1 parent 80e0c79 commit a45cd45
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 21 deletions.
15 changes: 15 additions & 0 deletions purchase_open_qty/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,29 @@ Contributors
------------

- Miquel Raïch <[email protected]>

- Andreas Dian Sukarno Putro <[email protected]>

- Kitti Upariphutthiphong <[email protected]>

- Eric Antones <[email protected]>

- Juany Davila <[email protected]>

- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Roca

- ``Trobz <https://trobz.com>``\ \_:

- Son Ho [email protected]

Other credits
-------------

The migration of this module from 16.0 to 17.0 was financially supported
by Camptocamp

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion purchase_open_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Purchase Open Qty",
"summary": "Allows to identify the purchase orders that have quantities "
"pending to invoice or to receive.",
"version": "16.0.2.0.1",
"version": "17.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchases",
Expand Down
24 changes: 12 additions & 12 deletions purchase_open_qty/init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@
logger = logging.getLogger(__name__)


def pre_init_hook(cr):
def pre_init_hook(env):
"""
The objective of this hook is to speed up the installation
of the module on an existing Odoo instance.
"""
store_field_qty_to_receive_and_invoice(cr)
store_field_qty_to_receive_and_invoice(env)


def store_field_qty_to_receive_and_invoice(cr):
cr.execute(
def store_field_qty_to_receive_and_invoice(env):
env.cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='purchase_order_line' AND
column_name='qty_to_receive'"""
)
if not cr.fetchone():
if not env.cr.fetchone():
logger.info("Creating field qty_to_receive on purchase_order_line")
cr.execute(
env.cr.execute(
"""
ALTER TABLE purchase_order_line ADD COLUMN qty_to_receive float;
COMMENT ON COLUMN purchase_order_line.qty_to_receive IS
'Qty to Receive';
"""
)

cr.execute(
env.cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='purchase_order_line' AND
column_name='qty_to_invoice'"""
)
if not cr.fetchone():
if not env.cr.fetchone():
logger.info("Creating field qty_to_invoice on purchase_order_line")
cr.execute(
env.cr.execute(
"""
ALTER TABLE purchase_order_line ADD COLUMN qty_to_invoice float;
COMMENT ON COLUMN purchase_order_line.qty_to_invoice IS
Expand All @@ -52,7 +52,7 @@ def store_field_qty_to_receive_and_invoice(cr):
"Computing values for fields qty_to_receive and qty_to_invoice"
" on purchase_order_line"
)
cr.execute(
env.cr.execute(
"""
UPDATE purchase_order_line pol
SET qty_to_invoice = pol.qty_received - pol.qty_invoiced
Expand All @@ -61,7 +61,7 @@ def store_field_qty_to_receive_and_invoice(cr):
WHERE t.purchase_method = 'receive' AND pol.product_id = p.id
"""
)
cr.execute(
env.cr.execute(
"""
UPDATE purchase_order_line pol
SET qty_to_invoice = pol.product_qty - pol.qty_invoiced
Expand All @@ -70,7 +70,7 @@ def store_field_qty_to_receive_and_invoice(cr):
WHERE t.purchase_method != 'receive' AND pol.product_id = p.id
"""
)
cr.execute(
env.cr.execute(
"""
UPDATE purchase_order_line
SET qty_to_receive = pol.qty
Expand Down
2 changes: 1 addition & 1 deletion purchase_open_qty/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PurchaseOrderLine(models.Model):
"qty_received",
)
def _compute_qty_to_receive(self):
service_lines = self.filtered(lambda l: l.product_id.type == "service")
service_lines = self.filtered(lambda line: line.product_id.type == "service")
for line in self - service_lines:
total = 0.0
for move in line.move_ids.filtered(
Expand Down
3 changes: 3 additions & 0 deletions purchase_open_qty/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
- Juany Davila \<<[email protected]>\>
- [Tecnativa](https://www.tecnativa.com):
- Carlos Roca
- `Trobz <https://trobz.com>`_:

* Son Ho <[email protected]>
1 change: 1 addition & 0 deletions purchase_open_qty/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp
14 changes: 12 additions & 2 deletions purchase_open_qty/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ <h1 class="title">Purchase Open Qty</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -417,10 +418,19 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Carlos Roca</li>
</ul>
</li>
<li><tt class="docutils literal">Trobz <span class="pre">&lt;https://trobz.com&gt;</span></tt>_:<ul>
<li>Son Ho <a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p>The migration of this module from 16.0 to 17.0 was financially supported
by Camptocamp</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">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>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
5 changes: 2 additions & 3 deletions purchase_open_qty/tests/test_purchase_open_qty.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_compute_qty_to_invoice_and_receive(self):
# Now we receive the products
for picking in self.purchase_order_2.picking_ids:
picking.action_confirm()
picking.move_ids.write({"quantity_done": 5.0})
picking.move_ids.write({"quantity": 5.0})
picking.button_validate()

# The value is computed when you run it as at user but not in the test
Expand Down Expand Up @@ -190,8 +190,7 @@ def test_search_qty_to_invoice_and_receive(self):
)
self.assertFalse(
self.purchase_order_2.id not in found.ids,
"Expected PO %s not to be in POs %s"
% (self.purchase_order_2.id, found.ids),
f"Expected PO {self.purchase_order_2.id} not to be in POs {found.ids}",
)

def test_03_po_line_with_services(self):
Expand Down
4 changes: 2 additions & 2 deletions purchase_open_qty/views/purchase_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<field name="qty_received" position="before">
<field
name="qty_to_receive"
attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"
column_invisible="parent.state not in ('purchase', 'done')"
optional="hide"
/>
</field>
<field name="qty_invoiced" position="before">
<field
name="qty_to_invoice"
attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"
column_invisible="parent.state not in ('purchase', 'done')"
optional="hide"
/>
</field>
Expand Down

0 comments on commit a45cd45

Please sign in to comment.