Skip to content

Commit

Permalink
[MIG] purchase_blanket_order: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoMForgeFlow committed Jan 19, 2024
1 parent dfb78d4 commit 771f942
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 27 deletions.
10 changes: 5 additions & 5 deletions purchase_blanket_order/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Purchase Blanket Orders
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_blanket_order
:target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_blanket_order
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_blanket_order
:target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_blanket_order
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -100,7 +100,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_blanket_order%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_blanket_order%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -133,6 +133,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/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/15.0/purchase_blanket_order>`_ project on GitHub.
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/16.0/purchase_blanket_order>`_ 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 purchase_blanket_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Purchase",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"version": "15.0.2.0.1",
"version": "16.0.2.0.1",
"website": "https://github.com/OCA/purchase-workflow",
"summary": "Purchase Blanket Orders",
"depends": [
Expand Down
4 changes: 2 additions & 2 deletions purchase_blanket_order/models/blanket_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def onchange_partner_id(self):
self.fiscal_position_id = (
self.env["account.fiscal.position"]
.with_context(company_id=self.company_id.id)
.get_fiscal_position(self.partner_id.id)
._get_fiscal_position(partner=self.partner_id)
)

self.currency_id = (
Expand Down Expand Up @@ -329,7 +329,7 @@ def expire_orders(self):
[("state", "=", "open"), ("validity_date", "<=", today)]
)
expired_orders.modified(["validity_date"])
expired_orders.recompute()
expired_orders.env.flush_all()

@api.model
def _search_original_uom_qty(self, operator, value):
Expand Down
15 changes: 9 additions & 6 deletions purchase_blanket_order/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ def onchange_product_id(self):
return self.get_assigned_bo_line()
return res

@api.onchange("product_qty", "product_uom")
def _onchange_quantity(self):
res = super()._onchange_quantity()
if self.product_id and not self.env.context.get("skip_blanket_find", False):
return self.get_assigned_bo_line()
@api.depends("product_qty", "product_uom")
def _compute_price_unit_and_date_planned_and_name(self):
res = super()._compute_price_unit_and_date_planned_and_name()
for rec in self:
if rec.product_id and not rec.env.context.get("skip_blanket_find", False):
return rec.get_assigned_bo_line()
return res

@api.onchange("blanket_order_line")
Expand All @@ -151,7 +152,9 @@ def onchange_blanket_order_line(self):
self.taxes_id = bol.taxes_id

Check warning on line 152 in purchase_blanket_order/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_blanket_order/models/purchase_order.py#L152

Added line #L152 was not covered by tests
else:
self._compute_tax_id()
self.with_context(skip_blanket_find=True)._onchange_quantity()
self.with_context(
skip_blanket_find=True
)._compute_price_unit_and_date_planned_and_name()

@api.constrains("date_planned")
def check_date_planned(self):
Expand Down
7 changes: 3 additions & 4 deletions purchase_blanket_order/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 Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">Purchase Blanket Orders</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7237471164928b8665c603ac9943005b2d6332ed46da07c0dd2e40b0862a793c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/purchase-workflow/tree/15.0/purchase_blanket_order"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_blanket_order"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/purchase-workflow/tree/16.0/purchase_blanket_order"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_blanket_order"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>A purchase blanket order is a pre-agreement to purchase a certain number of
quantities of products at a specific price. From a confirmed blanket order,
the users can create new purchase orders at such price, until the blanket
Expand Down Expand Up @@ -437,7 +436,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_blanket_order%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_blanket_order%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -464,7 +463,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">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/purchase-workflow/tree/15.0/purchase_blanket_order">OCA/purchase-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/16.0/purchase_blanket_order">OCA/purchase-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
55 changes: 53 additions & 2 deletions purchase_blanket_order/tests/test_purchase_blanket_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ def setUp(self):
self.blanket_order_line_obj = self.env["purchase.blanket.order.line"]
self.blanket_order_wiz_obj = self.env["purchase.blanket.order.wizard"]

self.user_test = self.env["res.users"].create(
{"name": "Test user", "login": "test_login"}
)
self.partner = self.env["res.partner"].create(
{"name": "TEST SUPPLIER", "supplier_rank": 1}
)
self.payment_term = self.env.ref("account.account_payment_term_30days")

# Seller IDS
seller = self.env["product.supplierinfo"].create(
{"name": self.partner.id, "price": 30.0}
{"partner_id": self.partner.id, "price": 30.0}
)

self.product = self.env["product.product"].create(
Expand Down Expand Up @@ -111,7 +114,7 @@ def test_01_create_blanket_order_flow(self):
blanket_order._search_received_uom_qty(">=", 0.0)
blanket_order._search_remaining_uom_qty(">=", 0.0)

def test__02_create_purchase_orders_from_blanket_order(self):
def test_02_create_purchase_orders_from_blanket_order(self):
"""We create a blanket order and create two purchase orders"""
blanket_order = self.blanket_order_obj.create(
{
Expand Down Expand Up @@ -226,3 +229,51 @@ def test_03_create_purchase_orders_from_blanket_order_line(self):

self.assertEqual(bo_lines[0].remaining_uom_qty, 10.0)
self.assertEqual(bo_lines[1].remaining_uom_qty, 30.0)

def test_04_constraints_blanket_order(self):
"""We create a blanket order and check constraints"""
blanket_order = self.blanket_order_obj.create(
{
"partner_id": self.partner.id,
"partner_ref": "REF",
"validity_date": fields.Date.to_string(self.tomorrow),
"payment_term_id": self.payment_term.id,
"line_ids": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"original_uom_qty": 20.0,
"price_unit": 30.0,
},
)
],
}
)
blanket_order.write({"partner_id": False})
blanket_order.onchange_partner_id()
self.assertFalse(blanket_order.payment_term_id)
self.assertFalse(blanket_order.fiscal_position_id)

self.partner.user_id = self.user_test
blanket_order.write({"partner_id": self.partner.id})
blanket_order.onchange_partner_id()
self.assertEqual(blanket_order.user_id, self.user_test)
blanket_order.sudo().action_confirm()
self.assertEqual(blanket_order.state, "open")

# remove open BO
with self.assertRaises(UserError):
blanket_order.sudo().unlink()

wizard1 = self.blanket_order_wiz_obj.with_context(
active_id=blanket_order.id, active_model="purchase.blanket.order"
).create({})
wizard1.line_ids[0].write({"qty": 10.0})
wizard1.sudo().create_purchase_order()

# cancel BO with PO not cancelled
with self.assertRaises(UserError):
blanket_order.sudo().action_cancel()
2 changes: 1 addition & 1 deletion purchase_blanket_order/tests/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):

# Seller IDS
seller = self.env["product.supplierinfo"].create(
{"name": self.partner.id, "price": 30.0}
{"partner_id": self.partner.id, "price": 30.0}
)

self.product = self.env["product.product"].create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
groups="base.group_multi_company"
options="{'no_create': True}"
/>
<field name="company_id" invisible="1" />
</group>
</group>
<group name="group_bottom">
Expand Down
8 changes: 4 additions & 4 deletions purchase_blanket_order/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
>purchase.order.from.blanket.form - disable adding lines</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field
name="groups_id"
eval="[(6,0,[ref('purchase_blanket_order.purchase_blanket_orders_disable_adding_lines')])]"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']//tree" position="attributes">
<attribute name="create">blanket_order_id==False</attribute>
<field
name="groups"
eval="[(6,0,[ref('purchase_blanket_order.purchase_blanket_orders_disable_adding_lines')])]"
/>
</xpath>
</field>
</record>
Expand Down
4 changes: 2 additions & 2 deletions purchase_blanket_order/wizard/create_purchase_orders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">purchase.blanket.order.wizard</field>
<field name="arch" type="xml">
<form string="Create Purchase Order">
<group>
<div>
<field name="line_ids" nolabel="1">
<tree create="false" editable="bottom">
<field name="blanket_line_id" invisible="1" />
Expand All @@ -18,7 +18,7 @@
<field name="qty" />
</tree>
</field>
</group>
</div>
<footer>
<button
name="create_purchase_order"
Expand Down

0 comments on commit 771f942

Please sign in to comment.