Skip to content

Commit

Permalink
[MOV] product_packaging_type_required becomes product_packaging_level…
Browse files Browse the repository at this point in the history
…_required
  • Loading branch information
trisdoan committed Dec 16, 2024
1 parent 5b37dd1 commit d98a495
Show file tree
Hide file tree
Showing 26 changed files with 170 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
===============================
Product Packaging Type Required
===============================
================================
Product Packaging Level Required
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -17,21 +17,21 @@ Product Packaging Type Required
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/18.0/product_packaging_type_required
:target: https://github.com/OCA/product-attribute/tree/18.0/product_packaging_level_required
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_type_required
:target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_level_required
: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/product-attribute&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to mark a product packaging type as required.
This module allows to mark a product packaging level as required.

A cron creates the missing product packages if the related packaging
type is required.
level is required.

**Table of contents**

Expand All @@ -41,18 +41,18 @@ type is required.
Usage
=====

To set a packaging type as required:
To set a packaging level as required:

1. Go to *Sales > Configuration > Products > Product Packaging Type*.
2. You can make a type required
1. Go to *Inventory > Configuration > Product Packaging Level*.
2. You can make a level required

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_packaging_type_required%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_packaging_level_required%0Aversion:%2018.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 @@ -71,13 +71,14 @@ Contributors

- Damien Crier <[email protected]>
- Simone Orsi <[email protected]>

- Phuc Tran Thanh <phuc@trobz.com>
- Phuc Tran Thanh <[email protected]>
- Tris Doan <tridm@trobz.com>

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

The development of this module has been financially supported by:
The development and migration of this module has been financially
supported by:

- Camptocamp

Expand Down Expand Up @@ -105,6 +106,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk| |maintainer-dcrier|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/18.0/product_packaging_type_required>`_ project on GitHub.
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/18.0/product_packaging_level_required>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product Packaging Type Required",
"version": "14.0.1.1.0",
"name": "Product Packaging Level Required",
"version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Product",
"summary": "Product Packaging Type Required",
"summary": "Product Packaging Level Required",
"author": "Camptocamp, " "Odoo Community Association (OCA)",
"maintainers": ["simahawk", "dcrier"],
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"depends": ["product", "product_packaging_type"],
"data": ["data/cron.xml", "views/product_packaging_type_view.xml"],
"depends": ["product_packaging_level"],
"data": ["data/cron.xml", "views/product_packaging_level_views.xml"],
"installable": True,
"auto_install": False,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
<odoo noupdate="1">
<record forcecreate="True" id="ir_cron_packaging_required" model="ir.cron">
<field name="name">Packaging Required</field>
<field
ref="product_packaging_type.model_product_packaging_type"
name="model_id"
/>
<field ref="stock.model_stock_package_type" name="model_id" />
<field name="state">code</field>
<field name="code">model.cron_check_create_required_packaging()</field>
<field name="code">model.cron_check_create_required_packaging_level()</field>
<field eval="False" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">20</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
</record>
</odoo>
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions product_packaging_level_required/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_packaging_level
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,30 @@
_logger = logging.getLogger(__name__)


class ProductPackagingType(models.Model):
_inherit = "product.packaging.type"
class ProductPackagingLevel(models.Model):
_inherit = "product.packaging.level"

required = fields.Boolean()

@api.model
def cron_check_create_required_packaging(self):
"""Create required packaging for each consumable product if missing."""
existing_products = self.env["product.product"].search(
[("type", "in", ("product", "consu"))]
)
required_packaging_types = self.search([("required", "=", True)])
def cron_check_create_required_packaging_level(self):
"""Create required packaging level for each consumable product if missing."""
existing_products = self.env["product.product"].search([("type", "=", "consu")])
required_packaging_levels = self.search([("required", "=", True)])
packaging_model = self.env["product.packaging"]
create_values = []
for product in existing_products:
packagings = product.packaging_ids
existing_packaging_types = packagings.mapped("packaging_type_id")
missing_packaging_types = (
required_packaging_types - existing_packaging_types
existing_packaging_levels = packagings.mapped("packaging_level_id")
missing_packaging_levels = (
required_packaging_levels - existing_packaging_levels
)
if not missing_packaging_types:
if not missing_packaging_levels:
continue
create_values.extend(
[
ptype._prepare_required_packaging_vals(product)
for ptype in missing_packaging_types
plevel._prepare_required_packaging_vals(product)
for plevel in missing_packaging_levels
]
)
if create_values:
Expand All @@ -47,7 +45,7 @@ def cron_check_create_required_packaging(self):

def _prepare_required_packaging_vals(self, product):
res = {
"packaging_type_id": self.id,
"packaging_level_id": self.id,
"name": self.name,
"product_id": product.id,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- [Camptocamp](https://www.camptocamp.com)
- Damien Crier \<<[email protected]>\>
- Simone Orsi \<<[email protected]>\>
- Phuc Tran Thanh \<<[email protected]>\>
- Phuc Tran Thanh \<<[email protected]>\>
- Tris Doan \<<[email protected]>\>
3 changes: 3 additions & 0 deletions product_packaging_level_required/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development and migration of this module has been financially supported by:

- Camptocamp
4 changes: 4 additions & 0 deletions product_packaging_level_required/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module allows to mark a product packaging level as required.

A cron creates the missing product packages if the related packaging
level is required.
4 changes: 4 additions & 0 deletions product_packaging_level_required/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To set a packaging level as required:
1. Go to *Inventory \> Configuration \> Product Packaging
Level*.
2. You can make a level required
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Product Packaging Type Required</title>
<title>Product Packaging Level Required</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,19 +360,19 @@
</style>
</head>
<body>
<div class="document" id="product-packaging-type-required">
<h1 class="title">Product Packaging Type Required</h1>
<div class="document" id="product-packaging-level-required">
<h1 class="title">Product Packaging Level Required</h1>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e59d8c7902f6e14f3419fc352a13fa97a41db7ea8b7dc2afdbf8ae64a8996ac5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/product-attribute/tree/18.0/product_packaging_type_required"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_type_required"><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/product-attribute&amp;target_branch=18.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 mark a product packaging type as required.</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/product-attribute/tree/18.0/product_packaging_level_required"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_level_required"><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/product-attribute&amp;target_branch=18.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 mark a product packaging level as required.</p>
<p>A cron creates the missing product packages if the related packaging
type is required.</p>
level is required.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -389,18 +389,18 @@ <h1 class="title">Product Packaging Type Required</h1>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To set a packaging type as required:</p>
<p>To set a packaging level as required:</p>
<ol class="arabic simple">
<li>Go to <em>Sales &gt; Configuration &gt; Products &gt; Product Packaging Type</em>.</li>
<li>You can make a type required</li>
<li>Go to <em>Inventory &gt; Configuration &gt; Product Packaging Level</em>.</li>
<li>You can make a level required</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<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/product-attribute/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/product-attribute/issues/new?body=module:%20product_packaging_type_required%0Aversion:%2018.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/product-attribute/issues/new?body=module:%20product_packaging_level_required%0Aversion:%2018.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 @@ -417,14 +417,16 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a><ul>
<li>Damien Crier &lt;<a class="reference external" href="mailto:damien.crier&#64;camptocamp.com">damien.crier&#64;camptocamp.com</a>&gt;</li>
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simone.orsi&#64;camptocamp.com">simone.orsi&#64;camptocamp.com</a>&gt;</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p>
<p>The development and migration of this module has been financially
supported by:</p>
<ul class="simple">
<li>Camptocamp</li>
</ul>
Expand All @@ -440,7 +442,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/simahawk"><img alt="simahawk" src="https://github.com/simahawk.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/dcrier"><img alt="dcrier" src="https://github.com/dcrier.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/18.0/product_packaging_type_required">OCA/product-attribute</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/18.0/product_packaging_level_required">OCA/product-attribute</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
74 changes: 74 additions & 0 deletions product_packaging_level_required/tests/test_packaging_required.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2021 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
from odoo.tests import common
from odoo.tools.misc import mute_logger


class TestPackagingLevelRequired(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product = cls.env["product.template"].create(
{"name": "Product Test", "type": "consu"}
)
cls.default_level = cls.env.ref(
"product_packaging_level.product_packaging_level_default"
)
cls.default_level.write({"required": True})
cls.test_level = cls.env["product.packaging.level"].create(
{
"name": "Packaging Level Test",
"code": "TEST2",
"sequence": 2,
"required": True,
}
)
# Create packaging only for one of them
cls.pkg_box = cls.env["product.packaging"].create(
{
"name": "Box",
"product_id": cls.product.product_variant_ids.id,
"qty": 50,
"packaging_level_id": cls.default_level.id,
"barcode": "BOX",
}
)

@mute_logger(
"odoo.addons.product_packing_level_required.models.product_packaging_level"
)
def test_cron_create(self):
products_count = self.env["product.product"].search_count(
[("type", "=", "consu")]
)
count_packaging = self.env["product.packaging"].search_count
domain1 = [("packaging_level_id", "=", self.test_level.id)]
self.assertEqual(count_packaging(domain1), 0)

domain2 = [("packaging_level_id", "=", self.default_level.id)]
self.assertEqual(count_packaging(domain2), 1)

res = self.env[
"product.packaging.level"
].cron_check_create_required_packaging_level()
# We get one required packaging per level per product
self.assertEqual(count_packaging(domain1), products_count)
self.assertEqual(count_packaging(domain2), products_count)
# 1 was already created at the setup
created_count = (products_count * 2) - 1
self.assertEqual(res, f"CREATED {created_count} required packaging")

# Let's add another one
self.env["product.packaging.level"].create(
{
"name": "Packaging Level Test 3",
"code": "TEST3",
"sequence": 3,
"required": True,
}
)
res = self.env[
"product.packaging.level"
].cron_check_create_required_packaging_level()
self.assertEqual(res, f"CREATED {products_count} required packaging")
Loading

0 comments on commit d98a495

Please sign in to comment.