Skip to content

Commit

Permalink
[IMP] stock_barcodes_gs1_secondary_unit: Adapt to refactored stock_ba…
Browse files Browse the repository at this point in the history
…rcodes_gs1 module
  • Loading branch information
sergio-teruel committed Oct 26, 2023
1 parent 4e2c011 commit 7a39df0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 54 deletions.
11 changes: 7 additions & 4 deletions stock_barcodes_gs1_secondary_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Stock Barcodes GS1 Secondary Unit
=================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:870410a97d88dbf44555fddda5bfa1a03103a1edb31a832e5ad500e00296a90c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -20,10 +23,10 @@ Stock Barcodes GS1 Secondary Unit
:target: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes_gs1_secondary_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-barcode&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-barcode&target_branch=15.0
:alt: Try me on Runboat

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

This module extends barcode reader GS1 interface module to allow to read
package barcodes from secondary units model.
Expand All @@ -43,7 +46,7 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-barcode/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-barcode/issues/new?body=module:%20stock_barcodes_gs1_secondary_unit%0Aversion:%2015.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
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class ProductSecondaryUnit(models.Model):

barcode = fields.Char(
copy=False,
index=True,
help="International Article Number used for product identification.",
)
38 changes: 20 additions & 18 deletions stock_barcodes_gs1_secondary_unit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Stock Barcodes GS1 Secondary Unit</title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -366,45 +366,47 @@ <h1 class="title">Stock Barcodes GS1 Secondary Unit</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:870410a97d88dbf44555fddda5bfa1a03103a1edb31a832e5ad500e00296a90c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/stock-logistics-barcode/tree/15.0/stock_barcodes_gs1_secondary_unit"><img alt="OCA/stock-logistics-barcode" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--barcode-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes_gs1_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-barcode&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/stock-logistics-barcode/tree/15.0/stock_barcodes_gs1_secondary_unit"><img alt="OCA/stock-logistics-barcode" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--barcode-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes_gs1_secondary_unit"><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/stock-logistics-barcode&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>This module extends barcode reader GS1 interface module to allow to read
package barcodes from secondary units model.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>Read usage section from stock_barcodes module.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<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/stock-logistics-barcode/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 smashing it by providing a detailed and welcomed
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/stock-logistics-barcode/issues/new?body=module:%20stock_barcodes_gs1_secondary_unit%0Aversion:%2015.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="#id3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Sergio Teruel</li>
Expand All @@ -413,7 +415,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">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
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,31 @@

from odoo.tests import tagged

from odoo.addons.stock_barcodes.tests.test_stock_barcodes_picking import (
TestStockBarcodesPicking,
from odoo.addons.stock_barcodes_gs1.tests.test_stock_barcodes_gs1 import (
TestStockBarcodesGS1,
)


@tagged("post_install", "-at_install")
class TestStockBarcodesGS1SecondaryUnit(TestStockBarcodesPicking):
def setUp(self):
super().setUp()
self.barcode_secondary_uom = "01195011015300011714070410AB-123"
self.secondary_unit = self.env["product.secondary.unit"].create(
class TestStockBarcodesGS1SecondaryUnit(TestStockBarcodesGS1):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.barcode_secondary_uom = "018412598033094"
cls.secondary_unit = cls.env["product.secondary.unit"].create(
{
"product_tmpl_id": self.product_tracking.product_tmpl_id.id,
"product_tmpl_id": cls.product_tracking.product_tmpl_id.id,
"name": "box 8",
"uom_id": self.product_tracking.uom_id.id,
"uom_id": cls.product_tracking.uom_id.id,
"factor": 8.0,
"barcode": "19501101530001",
"barcode": "8412598033094",
}
)

def _test_wizard_scan_gs1_secondary_unit(self):
def test_wizard_scan_gs1_secondary_unit(self):
# Scanning barcode with package data
self.action_barcode_scanned(self.wiz_scan_picking, self.barcode_secondary_uom)
self.assertEqual(self.wiz_scan_picking.secondary_uom_id, self.secondary_unit)
self.wiz_scan_picking.secondary_uom_qty = 5.0
self.wiz_scan_picking.onchange_secondary_uom_qty()
self.assertEqual(self.wiz_scan_picking.product_qty, 40.0)

def _test_picking_wizard_scan_package_secondary_uom(self):
self.action_barcode_scanned(self.wiz_scan_picking, self.barcode_secondary_uom)
self.assertEqual(self.wiz_scan_picking.product_qty, 8.0)
sml = self.picking_in_01.move_line_ids.filtered(
lambda x: x.product_id == self.product_tracking
)
self.assertEqual(sml.secondary_uom_id, self.wiz_scan_picking.secondary_uom_id)
self.action_barcode_scanned(self.wiz_scan, self.barcode_secondary_uom)
self.assertEqual(self.wiz_scan.secondary_uom_id, self.secondary_unit)
self.wiz_scan.secondary_uom_qty = 5.0
self.wiz_scan.onchange_secondary_uom_qty()
self.assertEqual(self.wiz_scan.product_qty, 40.0)
20 changes: 12 additions & 8 deletions stock_barcodes_gs1_secondary_unit/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ def action_secondary_uom_scaned_post(self, secondary_uom):
if self.product_id != secondary_uom.product_tmpl_id.product_variant_id:
self.lot_id = False
self.product_id = secondary_uom.product_tmpl_id.product_variant_id
self.secondary_uom_qty = 0.0 if self.manual_entry else 1.0
self.product_qty = secondary_uom.factor * self.secondary_uom_qty
if self.manual_entry or self.is_manual_qty:
return
elif self.secondary_uom_id:
self.secondary_uom_qty = 1.0
self.product_qty = self.secondary_uom_id.factor * self.secondary_uom_qty
else:
self.secondary_uom_qty = 0.0
self.product_qty = 1.0

def _prepare_scan_log_values(self, log_detail=False):
vals = super()._prepare_scan_log_values(log_detail=log_detail)
Expand All @@ -50,22 +56,20 @@ def reset_qty(self):
self.secondary_uom_qty = 0
return res

def process_barcode_package(self, package_barcode, processed):
def _process_ai_01(self, gs1_list):
secondary_uom = self.env["product.secondary.unit"].search(
self._barcode_domain(package_barcode)
self._barcode_domain(self.barcode)
)
if not secondary_uom:
self._set_messagge_info(
"not_found", _("Barcode for product secondary uom not found")
)
return super().process_barcode_package(package_barcode, processed)
return super()._process_ai_01(gs1_list)
else:
if len(secondary_uom) > 1:
self._set_messagge_info(
"more_match", _("More than one secondary uom found")
)
return False
self.action_secondary_uom_scaned_post(secondary_uom)
return True

@api.onchange("product_id")
def onchange_product_id(self):
Expand Down

0 comments on commit 7a39df0

Please sign in to comment.