Skip to content

Commit

Permalink
[FIX] oxigen_stock_barcodes_gs1: Fix auto advance when you scan gs1 p…
Browse files Browse the repository at this point in the history
…roduct
  • Loading branch information
FrankC013 committed Jan 29, 2024
1 parent 8bf3b78 commit 5818739
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
4 changes: 2 additions & 2 deletions oxigen_stock_barcodes_gs1/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Oxigen stock barcodes GS1
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:18355e0b0e74e8f9587b341190e2f15a1f71d81a4811fa16e293278459f5529b
!! source digest: sha256:2580c1861591aef093578d851da478d6c965f38c50cfe353ce43edee1d99385c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -54,7 +54,7 @@ Contributors

* Lois Rilo <[email protected]>

* `NuoBiT <https://www.nuobit.com>`_:
* `NuoBiT Solutions S.L. <https://www.nuobit.com>`_:

* Frank Cespedes <[email protected]>
* Eric Antones <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions oxigen_stock_barcodes_gs1/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Oxigen stock barcodes GS1</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:18355e0b0e74e8f9587b341190e2f15a1f71d81a4811fa16e293278459f5529b
!! source digest: sha256:2580c1861591aef093578d851da478d6c965f38c50cfe353ce43edee1d99385c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/oxigensalud/odoo-addons/tree/14.0/oxigen_stock_barcodes_gs1"><img alt="oxigensalud/odoo-addons" src="https://img.shields.io/badge/github-oxigensalud%2Fodoo--addons-lightgray.png?logo=github" /></a></p>
<ul class="simple">
Expand Down Expand Up @@ -412,7 +412,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</ul>
</blockquote>
<ul class="simple">
<li><a class="reference external" href="https://www.nuobit.com">NuoBiT</a>:<ul>
<li><a class="reference external" href="https://www.nuobit.com">NuoBiT Solutions S.L.</a>:<ul>
<li>Frank Cespedes &lt;<a class="reference external" href="mailto:fcespedes&#64;nuobit.com">fcespedes&#64;nuobit.com</a>&gt;</li>
<li>Eric Antones &lt;<a class="reference external" href="mailto:eantones&#64;nuobit.com">eantones&#64;nuobit.com</a>&gt;</li>
</ul>
Expand Down
71 changes: 41 additions & 30 deletions oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,52 @@ class WizStockBarcodesRead(models.AbstractModel):
_inherit = "wiz.stock.barcodes.read"

def process_lot(self, barcode_decoded):
res = super().process_lot(barcode_decoded)
if self.product_id.tracking == "serial":
lot_barcode = barcode_decoded.get("21", False)
operation = getattr(self, "picking_id", False) or getattr(
self, "inventory_id", False
)
if not operation:
raise ValidationError(
_(
"This record has inconsistent data. Delete the record and recreate it."
)
super().process_lot(barcode_decoded)

Check warning on line 19 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L19

Added line #L19 was not covered by tests
if self.lot_id and (self.manual_entry or self.is_manual_qty):
self.product_qty += 1

def check_serial_lot_conditions(self, barcode_decoded):
operation = getattr(self, "picking_id", False) or getattr(

Check warning on line 24 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L24

Added line #L24 was not covered by tests
self, "inventory_id", False
)
if not operation:
raise ValidationError(

Check warning on line 28 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L28

Added line #L28 was not covered by tests
_(
"This record has inconsistent data. Delete the record and recreate it."
)
lot = self.env["stock.production.lot"].search(
[
("name", "=", lot_barcode),
("product_id", "=", self.product_id.id),
("company_id", "=", operation.company_id.id),
]
)
ref_barcode = barcode_decoded.get("10", False)
if lot and ref_barcode and lot.ref != ref_barcode:
self._set_messagge_info(
"not_found",
_(
"The lot %s has been found but the reference %s does not match."
% (lot_barcode, ref_barcode)
),
)
lot_barcode = barcode_decoded.get("21", False)
lot = self.env["stock.production.lot"].search(

Check warning on line 34 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L33-L34

Added lines #L33 - L34 were not covered by tests
[
("name", "=", lot_barcode),
("product_id", "=", self.product_id.id),
("company_id", "=", operation.company_id.id),
]
)
ref_barcode = barcode_decoded.get("10", False)

Check warning on line 41 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L41

Added line #L41 was not covered by tests
if lot and ref_barcode and lot.ref != ref_barcode:
self._set_messagge_info(

Check warning on line 43 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L43

Added line #L43 was not covered by tests
"not_found",
_(
"The lot %s has been found but the reference %s does not match."
% (lot_barcode, ref_barcode)
),
)
self.env.context = dict(self.env.context, ref_not_found=ref_barcode)
return lot, False
return lot, True

Check warning on line 52 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L50-L52

Added lines #L50 - L52 were not covered by tests

def process_lot_extended(self, barcode_decoded):
if self.product_id.tracking == "serial":
lot, result_ok = self.check_serial_lot_conditions(barcode_decoded)

Check warning on line 56 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L56

Added line #L56 was not covered by tests
if not result_ok:
return False

Check warning on line 58 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L58

Added line #L58 was not covered by tests
if not lot and self.option_group_id.create_lot:
lot = self._create_lot(barcode_decoded)
self.lot_id = lot

Check warning on line 61 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L60-L61

Added lines #L60 - L61 were not covered by tests
if self.lot_id and (self.manual_entry or self.is_manual_qty):
self.product_qty += 1
return res
else:
self.process_lot(barcode_decoded)
return True

Check warning on line 64 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L63-L64

Added lines #L63 - L64 were not covered by tests

# WARNING: override standard method
def process_barcode(self, barcode): # noqa: C901
Expand Down Expand Up @@ -114,7 +125,7 @@ def process_barcode(self, barcode): # noqa: C901
else:
lot_barcode = barcode_decoded.get("10", False)

Check warning on line 126 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L126

Added line #L126 was not covered by tests
if lot_barcode and self.product_id.tracking != "none":
if not self.process_lot(barcode_decoded):
if not self.process_lot_extended(barcode_decoded):
return False

Check warning on line 129 in oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py

View check run for this annotation

Codecov / codecov/patch

oxigen_stock_barcodes_gs1/wizard/stock_barcodes_read.py#L129

Added line #L129 was not covered by tests
processed = True
if product_qty and package_barcode:
Expand Down

0 comments on commit 5818739

Please sign in to comment.