Skip to content

Commit

Permalink
Merge PR #1559 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Mar 22, 2024
2 parents 28db8a2 + 8d070b3 commit e255e7d
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 14 deletions.
24 changes: 22 additions & 2 deletions product_lot_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Product Lot Sequence
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:dfe9a2666cd1599203c70fd159399022104a8f2df4808574a961f49e93399cf1
!! source digest: sha256:568bfc6b73360be36291cdcf8aa0d184a57b2701e2ff2798311977a8be099b31
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -73,6 +73,21 @@ To use this module:
* Create new Lot/Serial number
* Select the product and the next number of the product sequence will be automatically proposed

Known issues / Roadmap
======================

* There is an issue with the use of ir.sequence with the newer version of Odoo.

Mostly, when opening the detailed operations of an assigned picking for a product
tracked by serial numbers, Odoo systematically calls `_get_next_serial` even
if there is not any serial number to generate.
Moreover, the widget allowing to generate the serial numbers will not call
the sequence but only increment the number according to the next serial,
potentially leading to a sequence that is not in sync anymore with the created
serial numbers.

cf https://github.com/OCA/product-attribute/issues/1326

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

Expand All @@ -96,7 +111,12 @@ Contributors

* Adria Gil Sorribes <adria.gil@forgeflow.com>
* Domantas Girdžiūnas <domantas@vialaurea.lt>
* Akim Juillerat <akim.juillerat@camptocamp.com>

* `Camptocamp <https://www.camptocamp.com>`__:

* Akim Juillerat <akim.juillerat@camptocamp.com>
* Vincent Van Rossem <vincent.vanrossem@camptocamp.com>

* `Quartile <https://www.quartile.co>`__:

* Yoshi Tashiro
Expand Down
1 change: 1 addition & 0 deletions product_lot_sequence/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import product
from . import res_config_settings
from . import stock_lot
from . import stock_move
2 changes: 2 additions & 0 deletions product_lot_sequence/models/stock_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def create(self, vals_list):

@api.model
def _get_next_serial(self, company, product):
if "force_next_serial" in self.env.context:
return self.env.context.get("force_next_serial")
seq_policy = self._get_sequence_policy()
if seq_policy == "product":
seq = product.product_tmpl_id.lot_sequence_id
Expand Down
19 changes: 19 additions & 0 deletions product_lot_sequence/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def action_show_details(self):
"""Avoid calling and incrementing the sequence if not needed or already done"""
seq_policy = self.env["stock.lot"]._get_sequence_policy()
if seq_policy in ("product", "global"):
# If move is not supposed to assign serial pass empty string for next serial
if not self.display_assign_serial:
self = self.with_context(force_next_serial="")
# If the sequence was already called once, avoid calling it another time
elif self.next_serial:
self = self.with_context(force_next_serial=self.next_serial)
return super(StockMove, self).action_show_details()
7 changes: 6 additions & 1 deletion product_lot_sequence/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
* Adria Gil Sorribes <adria.gil@forgeflow.com>
* Domantas Girdžiūnas <domantas@vialaurea.lt>
* Akim Juillerat <akim.juillerat@camptocamp.com>

* `Camptocamp <https://www.camptocamp.com>`__:

* Akim Juillerat <akim.juillerat@camptocamp.com>
* Vincent Van Rossem <vincent.vanrossem@camptocamp.com>

* `Quartile <https://www.quartile.co>`__:

* Yoshi Tashiro
11 changes: 11 additions & 0 deletions product_lot_sequence/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* There is an issue with the use of ir.sequence with the newer version of Odoo.

Mostly, when opening the detailed operations of an assigned picking for a product
tracked by serial numbers, Odoo systematically calls `_get_next_serial` even
if there is not any serial number to generate.
Moreover, the widget allowing to generate the serial numbers will not call
the sequence but only increment the number according to the next serial,
potentially leading to a sequence that is not in sync anymore with the created
serial numbers.

cf https://github.com/OCA/product-attribute/issues/1326
41 changes: 30 additions & 11 deletions product_lot_sequence/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Product Lot Sequence</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:dfe9a2666cd1599203c70fd159399022104a8f2df4808574a961f49e93399cf1
!! source digest: sha256:568bfc6b73360be36291cdcf8aa0d184a57b2701e2ff2798311977a8be099b31
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/16.0/product_lot_sequence"><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-16-0/product-attribute-16-0-product_lot_sequence"><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=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Adds ability to define a lot sequence from the product which will be proposed upon creating new lots.</p>
Expand All @@ -380,11 +380,12 @@ <h1 class="title">Product Lot Sequence</h1>
</ul>
</li>
<li><a class="reference internal" href="#usage" id="toc-entry-4">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-5">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-6">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-7">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-8">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-9">Maintainers</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-5">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-6">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-7">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-8">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-9">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -424,36 +425,54 @@ <h1><a class="toc-backref" href="#toc-entry-4">Usage</a></h1>
<li>Select the product and the next number of the product sequence will be automatically proposed</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>There is an issue with the use of ir.sequence with the newer version of Odoo.</li>
</ul>
<p>Mostly, when opening the detailed operations of an assigned picking for a product
tracked by serial numbers, Odoo systematically calls <cite>_get_next_serial</cite> even
if there is not any serial number to generate.
Moreover, the widget allowing to generate the serial numbers will not call
the sequence but only increment the number according to the next serial,
potentially leading to a sequence that is not in sync anymore with the created
serial numbers.</p>
<p>cf <a class="reference external" href="https://github.com/OCA/product-attribute/issues/1326">https://github.com/OCA/product-attribute/issues/1326</a></p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-6">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_lot_sequence%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">
<h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-7">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow S.L.</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<ul class="simple">
<li>Adria Gil Sorribes &lt;<a class="reference external" href="mailto:adria.gil&#64;forgeflow.com">adria.gil&#64;forgeflow.com</a>&gt;</li>
<li>Domantas Girdžiūnas &lt;<a class="reference external" href="mailto:domantas&#64;vialaurea.lt">domantas&#64;vialaurea.lt</a>&gt;</li>
<li><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a>:<ul>
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
<li>Vincent Van Rossem &lt;<a class="reference external" href="mailto:vincent.vanrossem&#64;camptocamp.com">vincent.vanrossem&#64;camptocamp.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
<li>Yoshi Tashiro</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-10">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
52 changes: 52 additions & 0 deletions product_lot_sequence/tests/test_product_lot_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ def setUp(self):
super(TestProductLotSequence, self).setUp()
self.product_product = self.env["product.product"]
self.stock_production_lot = self.env["stock.lot"]
self.receipt_type = self.env.ref("stock.picking_type_in")
self.delivery_type = self.env.ref("stock.picking_type_out")

def _create_picking(self, picking_type, move_vals_list):
picking_form = Form(self.env["stock.picking"])
picking_form.picking_type_id = picking_type
for move_vals in move_vals_list:
with picking_form.move_ids_without_package.new() as move_form:
move_form.product_id = move_vals.get("product_id")
move_form.product_uom_qty = move_vals.get("product_uom_qty", 1.0)
move_form.product_uom = move_vals.get(
"product_uom", self.env.ref("uom.product_uom_unit")
)
picking = picking_form.save()
picking.action_confirm()
return picking

def test_product_sequence(self):
self.assertEqual(self.stock_production_lot._get_sequence_policy(), "product")
Expand Down Expand Up @@ -86,3 +102,39 @@ def test_lot_onchange_product_id_global(self):
lot_form.product_id = product
lot = lot_form.save()
self.assertEqual(lot.name, next_sequence_number)

def test_open_detailed_operations(self):
# Required for `product_uom` to be visible in the view
self.env.user.groups_id += self.env.ref("uom.group_uom")

self.env["ir.config_parameter"].set_param(
"product_lot_sequence.policy", "global"
)
seq = self.env["ir.sequence"].search([("code", "=", "stock.lot.serial")])
first_next_sequence_number = seq.get_next_char(seq.number_next_actual)
product = self.product_product.create(
{"name": "Test global", "tracking": "serial"}
)
delivery_picking = self._create_picking(
self.delivery_type, [{"product_id": product}]
)
delivery_move = delivery_picking.move_ids
self.assertFalse(delivery_move.next_serial)
delivery_move.action_show_details()
self.assertFalse(delivery_move.next_serial)
self.assertEqual(
seq.get_next_char(seq.number_next_actual), first_next_sequence_number
)
receipt_picking = self._create_picking(
self.receipt_type, [{"product_id": product}]
)
receipt_move = receipt_picking.move_ids
self.assertFalse(receipt_move.next_serial)
receipt_move.action_show_details()
self.assertEqual(receipt_move.next_serial, first_next_sequence_number)
new_next_sequence_number = seq.get_next_char(seq.number_next_actual)
self.assertNotEqual(new_next_sequence_number, first_next_sequence_number)
receipt_move.action_show_details()
self.assertEqual(
new_next_sequence_number, seq.get_next_char(seq.number_next_actual)
)

0 comments on commit e255e7d

Please sign in to comment.