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 31, 2024
1 parent a03e870 commit c3e5612
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 35 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
8 changes: 2 additions & 6 deletions purchase_blanket_order/models/blanket_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class BlanketOrder(models.Model):
_description = "Purchase Blanket Order"
_order = "date_start desc, id desc"

@api.model
def _default_currency(self):
return self.env.user.company_id.currency_id

@api.model
def _default_company(self):
return self.env.user.company_id
Expand Down Expand Up @@ -227,7 +223,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 +325,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
2 changes: 1 addition & 1 deletion purchase_blanket_order/models/purchase_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PurchaseConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

group_purchase_blanket_disable_adding_lines = fields.Boolean(
string="Disable adding more lines to SOs",
string="Disable adding more lines to POs",
implied_group="purchase_blanket_order."
"purchase_blanket_orders_disable_adding_lines",
)
19 changes: 12 additions & 7 deletions purchase_blanket_order/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

blanket_order_line = fields.Many2one(
comodel_name="purchase.blanket.order.line", copy=False
comodel_name="purchase.blanket.order.line",
copy=False,
domain="[('product_id', '=', product_id)]",
)

def _get_assigned_bo_line(self, bo_lines):
Expand Down Expand Up @@ -126,11 +128,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 +154,9 @@ def onchange_blanket_order_line(self):
self.taxes_id = bol.taxes_id

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

View check run for this annotation

Codecov / codecov/patch

purchase_blanket_order/models/purchase_order.py#L154

Added line #L154 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
76 changes: 73 additions & 3 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 All @@ -33,6 +36,7 @@ def setUp(self):
"type": "consu",
"uom_id": self.env.ref("uom.product_uom_unit").id,
"default_code": "PROD_DEL01",
"description_purchase": "Purchase Description",
}
)
self.product2 = self.env["product.product"].create(
Expand Down Expand Up @@ -65,18 +69,26 @@ def test_01_create_blanket_order_flow(self):
0,
{
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"original_uom_qty": 20.0,
"price_unit": 0.0, # will be updated later
"product_uom": self.product.uom_id.id,
},
)
],
}
)
blanket_order.sudo().onchange_partner_id()
blanket_order.line_ids[0].write({"product_uom": False})
blanket_order.line_ids[0].sudo().onchange_product()
blanket_order._compute_line_count()
blanket_order._compute_uom_qty()
name = (
"[{}] {}".format(self.product.name, self.product.code)
+ "\n"
+ self.product.description_purchase
)
self.assertEqual(blanket_order.line_ids[0].name, name)
self.assertEqual(blanket_order.line_ids[0].product_uom, self.product.uom_id)

self.assertEqual(blanket_order.state, "draft")
self.assertEqual(blanket_order.line_ids[0].price_unit, 30.0)
Expand Down Expand Up @@ -111,7 +123,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 +238,61 @@ 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})
res = wizard1.sudo().create_purchase_order()
po = self._get_po_from_wizard(res)

# cancel BO with PO not cancelled
with self.assertRaises(UserError):
blanket_order.sudo().action_cancel()

po.button_cancel()
blanket_order.sudo().action_cancel()

with self.assertRaises(UserError):
# Blanket order expired
self.blanket_order_wiz_obj.with_context(
active_id=blanket_order.id, active_model="purchase.blanket.order"
).create({})
17 changes: 16 additions & 1 deletion purchase_blanket_order/tests/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import date, timedelta

from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests import common


Expand All @@ -17,11 +18,14 @@ def setUp(self):
self.partner = self.env["res.partner"].create(
{"name": "TEST SUPPLIER", "supplier_rank": 1}
)
self.partner_2 = self.env["res.partner"].create(
{"name": "TEST SUPPLIER 2", "supplier_rank": 2}
)
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 @@ -49,6 +53,9 @@ def setUp(self):
self.validity = date.today() + timedelta(days=365)
self.date_schedule_1 = date.today() + timedelta(days=10)
self.date_schedule_2 = date.today() + timedelta(days=20)
self.currency_test = self.env["res.currency"].create(
{"name": "Test Currency", "symbol": "T"}
)

def create_blanket_order_01(self):
blanket_order = self.blanket_order_obj.create(
Expand Down Expand Up @@ -200,3 +207,11 @@ def test_02_create_purchase_order(self):
]
)
self.assertEqual(po_line.blanket_order_line, bo_line_assigned)

# change currency of the PO line
with self.assertRaises(ValidationError):
po.write({"currency_id": self.currency_test})

# change partner of the PO line
with self.assertRaises(ValidationError):
po.write({"partner_id": self.partner_2})
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
2 changes: 1 addition & 1 deletion purchase_blanket_order/views/purchase_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="o_setting_right_pane">
<label for="group_purchase_blanket_disable_adding_lines" />
<div class="text-muted">
Disable adding more lines to SOs from Blanket Orders
Disable adding more lines to POs from Blanket Orders
</div>
</div>
</div>
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 c3e5612

Please sign in to comment.