Skip to content

Commit

Permalink
[MIG] sale_restricted_qty: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Oct 4, 2023
1 parent acfd498 commit 67022aa
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 61 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# generated from manifests external_dependencies
openupgradelib
15 changes: 9 additions & 6 deletions sale_restricted_qty/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale order min quantity
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9d34c5ce0bf0071dd40afa3f708f0f3d3f2098e4ca0d4b26d65bb1a8a40a23e0
!! source digest: sha256:11c109b03c7404989c3814a5675fcc5ae0cb3088674059b409bc202355156177
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Sale order min quantity
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/14.0/sale_restricted_qty
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_restricted_qty
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_restricted_qty
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_restricted_qty
: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/sale-workflow&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -64,7 +64,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-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/sale-workflow/issues/new?body=module:%20sale_restricted_qty%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_restricted_qty%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 All @@ -84,6 +84,9 @@ Contributors
* `Ooops <https://www.ooops404.com/>`_:

* Ashish Hirpara <https://ashish-hirpara.com>
* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -106,6 +109,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ashishhirapara|

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/14.0/sale_restricted_qty>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_restricted_qty>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion sale_restricted_qty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models
from .hooks import rename_module
7 changes: 2 additions & 5 deletions sale_restricted_qty/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# Copyright 2019 Akretion (<http://www.akretion.com>)
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale order min quantity",
"version": "14.0.1.1.1",
"version": "16.0.1.0.0",
"category": "Sales Management",
"author": "Akretion, Odoo Community Association (OCA)",
"contributors": ["Ashish Hirpara"],
"maintainers": ["ashishhirapara"],
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"external_dependencies": {
"python": ["openupgradelib"],
},
"depends": ["sale_management"],
"data": [
"views/product_category_views.xml",
"views/product_template_views.xml",
"views/product_product_views.xml",
"views/sale_views.xml",
],
"pre_init_hook": "rename_module",
"installable": True,
}
19 changes: 0 additions & 19 deletions sale_restricted_qty/hooks.py

This file was deleted.

19 changes: 18 additions & 1 deletion sale_restricted_qty/models/product_category.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
# Copyright 2019 Akretion
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class ProductCategory(models.Model):
_name = "product.category"
_inherit = ["product.category", "product.restricted.qty.mixin"]

sale_multiple_qty = fields.Float(
recursive=True,
)
sale_min_qty = fields.Float(
recursive=True,
)
force_sale_min_qty = fields.Boolean(
recursive=True,
)
sale_max_qty = fields.Float(
recursive=True,
)
force_sale_max_qty = fields.Boolean(
recursive=True,
)

def _get_sale_restricted_qty(self):
res = super()._get_sale_restricted_qty()
force_sale_min_qty = False
Expand Down
22 changes: 16 additions & 6 deletions sale_restricted_qty/models/sale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019 Akretion
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
Expand Down Expand Up @@ -56,8 +57,11 @@ def check_constraint_restricted_qty(self):
)
for line in line_to_test:
invaild_min_lines.append(
_('Product "%s": Min Quantity %s.')
% (line.product_id.name, line.sale_min_qty)
_(
'Product "%(product)s": Min Quantity %(min_qty)s.',
product=line.product_id.name,
min_qty=line.sale_min_qty,
)
)

if invaild_min_lines:
Expand All @@ -74,8 +78,11 @@ def check_constraint_restricted_qty(self):
)
for line in line_to_test:
invaild_max_lines.append(
_('Product "%s": max Quantity %s.')
% (line.product_id.name, line.sale_max_qty)
_(
'Product "%(product)s": max Quantity %(max_qty)s.',
product=line.product_id.name,
max_qty=line.sale_max_qty,
)
)

if invaild_max_lines:
Expand All @@ -90,8 +97,11 @@ def check_constraint_restricted_qty(self):
line_to_test = self.filtered(lambda sl: sl.is_qty_not_multiple_qty)
for line in line_to_test:
invaild_multiple_lines.append(
_('Product "%s": multiple Quantity %s.')
% (line.product_id.name, line.sale_multiple_qty)
_(
'Product "%(product)s": multiple Quantity %(multiple_qty)s.',
product=line.product_id.name,
multiple_qty=line.sale_multiple_qty,
)
)

if invaild_multiple_lines:
Expand Down
3 changes: 3 additions & 0 deletions sale_restricted_qty/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
* `Ooops <https://www.ooops404.com/>`_:

* Ashish Hirpara <https://ashish-hirpara.com>
* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <[email protected]>
12 changes: 8 additions & 4 deletions sale_restricted_qty/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Sale order min quantity</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9d34c5ce0bf0071dd40afa3f708f0f3d3f2098e4ca0d4b26d65bb1a8a40a23e0
!! source digest: sha256:11c109b03c7404989c3814a5675fcc5ae0cb3088674059b409bc202355156177
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/sale-workflow/tree/14.0/sale_restricted_qty"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_restricted_qty"><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/sale-workflow&amp;target_branch=14.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/sale-workflow/tree/16.0/sale_restricted_qty"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_restricted_qty"><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/sale-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>This module allows to define min, max and multiple order quantity on product.
Min and Max order quantity is either required or recommanded.
If you check “Force mini/max Qty” on product the min/max qty do not block sale
Expand Down Expand Up @@ -418,7 +418,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/sale-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/sale-workflow/issues/new?body=module:%20sale_restricted_qty%0Aversion:%2014.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/sale-workflow/issues/new?body=module:%20sale_restricted_qty%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 @@ -437,6 +437,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Ashish Hirpara &lt;<a class="reference external" href="https://ashish-hirpara.com">https://ashish-hirpara.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -448,7 +452,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/ashishhirapara"><img alt="ashishhirapara" src="https://github.com/ashishhirapara.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_restricted_qty">OCA/sale-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/16.0/sale_restricted_qty">OCA/sale-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
20 changes: 4 additions & 16 deletions sale_restricted_qty/tests/test_sale.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2019 Akretion
# Update (Migration) 2022 Ooops - Ashish Hirpara <[email protected]>
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import odoo.tests.common as common
Expand Down Expand Up @@ -49,31 +50,18 @@ def setUp(self):
}
)

def refrech_sale_values(self, sale_order):
sale_order.order_line._compute_sale_restricted_qty()
sale_order.order_line.product_id_change()
sale_order.order_line._compute_is_qty_less_min_qty()
sale_order.order_line._compute_is_qty_bigger_max_qty()
sale_values = sale_order._convert_to_write(sale_order._cache)
return sale_values

def test_check_sale_order_min_qty_required(self):
line_values = {"product_id": self.product.id, "product_uom_qty": 5.0}
self.product.manual_sale_min_qty = 10
# Create sale order line with Qty less than min Qty
with self.assertRaises(ValidationError):
sale_order = self.sale_order_model.new(
{"partner_id": self.partner.id, "order_line": [(0, 0, line_values)]}
)
sale_values = self.refrech_sale_values(sale_order)
sale_values.update(
self.sale_order_model.create(
{
"partner_shipping_id": sale_values["partner_id"],
"partner_invoice_id": sale_values["partner_id"],
"partner_id": self.partner.id,
"order_line": [(0, 0, line_values)],
"pricelist_id": 1,
}
)
self.sale_order_model.create(sale_values)
line_values["product_uom_qty"] = 12.0
# Create sale order line with Qty great then min Qty
self.sale_order = self.sale_order_model.create(
Expand Down
8 changes: 6 additions & 2 deletions sale_restricted_qty/views/product_product_views.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2023 Simone Rubino - Aion Tech
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="min_order_qty_product_product_form_view" model="ir.ui.view">
<field name="name">product.product.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<group name="invoicing" position="before">
<xpath expr="//page[@name='sales']/group[@name='sale']" position="after">
<group
name="sale_restricted_qty"
string="Sale restricted qty"
Expand Down Expand Up @@ -54,7 +58,7 @@
/>
</group>
</group>
</group>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 67022aa

Please sign in to comment.