Browse Source

OCA guidelines.

pull/501/head
François Kawala 5 years ago
parent
commit
3f74eac359
  1. 94
      pos_barcode_tare/README.rst
  2. 1
      pos_barcode_tare/__init__.py
  3. 39
      pos_barcode_tare/__openerp__.py
  4. 1
      pos_barcode_tare/models/__init__.py
  5. 8
      pos_barcode_tare/models/pos_config.py
  6. 2
      pos_barcode_tare/readme/CONTRIBUTORS.rst
  7. 12
      pos_barcode_tare/readme/DESCRIPTION.rst
  8. 1
      pos_barcode_tare/readme/USAGE.rst
  9. BIN
      pos_barcode_tare/static/description/icon.png
  10. 443
      pos_barcode_tare/static/description/index.html
  11. 20
      pos_barcode_tare/static/src/css/pos_barcode_tare.css
  12. 36
      pos_barcode_tare/static/src/js/barcode.js
  13. 20
      pos_barcode_tare/static/src/js/open_tare_screen_button.js
  14. 199
      pos_barcode_tare/static/src/js/pos_barcode_tare.js
  15. 139
      pos_barcode_tare/static/src/js/tare_screen.js
  16. 9
      pos_barcode_tare/static/src/xml/open_tare_screen_button.xml
  17. 19
      pos_barcode_tare/static/src/xml/pos_barcode_tare.xml
  18. 8
      pos_barcode_tare/views/pos_barcode_tare.xml
  19. 16
      pos_barcode_tare/views/pos_config_view.xml
  20. 12
      pos_barcode_tare/views/templates.xml

94
pos_barcode_tare/README.rst

@ -0,0 +1,94 @@
====================================================
Point of Sale - Tare barecode labels for loose goods
====================================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/9.0/pos_barcode_tare
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-9-0/pos-9-0-pos_barcode_tare
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/184/9.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This add-on enable POS to read and print tare barcodes. A tare barcode is used to sell loose goods in a bring your own
container (BYOC) scheme.
The BYOC scheme has four steps:
1. The cashier weights the container and sticks the tare bar code onto the customer's container.
2. The customer takes the desired quantity of the good s-he wants to buy.
3. The cashier weights the filled container and good, POS gives the corresponding price.
4. The cashier scans the tare bar code, POS removes the container's weight from the latest product of the order.
This add-on adds a news screen to POS to (web) print the tare barcode labels. This add-on enables POS to read a tare
barecode. When such a barcode is read, POS adjusts the weight of the latest article in the order list.
The new weight is equal to the total weight minus the tare weight. The price is updated accordingly to the weight
change.
**Table of contents**
.. contents::
:local:
Usage
=====
Install this add-on and configure the point of sale where you want to be able to use the tare barecode.
You can also select the label format in the point of sale configuration. The label printing is done using
web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or
the kiosk printing (chrome).
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/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
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_barcode_tare%0Aversion:%209.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.
Credits
=======
Authors
~~~~~~~
* Le Nid
Contributors
~~~~~~~~~~~~
- Le Nid
- CoopITEasy
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/9.0/pos_barcode_tare>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

1
pos_barcode_tare/__init__.py

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

39
pos_barcode_tare/__openerp__.py

@ -1,36 +1,21 @@
# -*- coding: utf-8 -*-
# @author: François Kawala
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "pos_barecode_tare",
'summary': """
Allows to scan a barcode to tare the latest product.
""",
'description': """
This add-on enable POS to read and print tare bar codes. A tare bar code is used to sell unpackaged goods in a
BYOC (bring your own container) scheme. This scheme has four steps:
1. The cashier weights the container and sticks the tare bar code onto the customer's container.
2. The customer takes the desired quantity of whatever good s-he wants.
3. The cashier weights the filled container and good, POS gives the corresponding price.
4. The cashier scans the tare bar code, POS removes the container's weight from the latest product of the order.
""",
'author': "Le Nid",
'website': "http://www.lenid.ch",
'name': "Point of Sale - Tare barecode labels for loose goods",
'version': '9.0.0.0.1',
'category': 'Point of Sale',
'version': '0.1',
# any module necessary for this one to work correctly
'summary': 'Point of Sale - Print and scan tare barecodes labels to sell loose goods.',
'author': "Le Nid, Odoo Community Association (OCA)",
'website': "https://github.com/OCA/pos",
'license': 'AGPL-3',
'depends': ['point_of_sale'],
# always loaded
'data': [
'views/templates.xml',
'views/pos_config_view.xml',
'views/pos_barcode_tare.xml',
],
'qweb': [
'static/src/xml/tare_screen.xml',
'static/src/xml/open_tare_screen_button.xml',
'static/src/xml/pos_barcode_tare.xml',
],
'installable': True,
}

1
pos_barcode_tare/models/__init__.py

@ -0,0 +1 @@
from . import pos_config

8
pos_barcode_tare/models/pos_config.py

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from openerp import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
tare_label_button = fields.Boolean('Show tare label button', help="Print tare labels with this POS")

2
pos_barcode_tare/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
- Le Nid
- CoopITEasy

12
pos_barcode_tare/readme/DESCRIPTION.rst

@ -0,0 +1,12 @@
This add-on enable POS to read and print tare barcodes. A tare barcode is used to sell loose goods in a bring your own container (BYOC) scheme.
The BYOC scheme has four steps:
1. The cashier weights the container and sticks the tare bar code onto the customer's container.
2. The customer takes the desired quantity of the good s-he wants to buy.
3. The cashier weights the filled container and good, POS gives the corresponding price.
4. The cashier scans the tare bar code, POS removes the container's weight from the latest product of the order.
This add-on adds a news screen to POS to (web) print the tare barcode labels. This add-on enables POS to read a tare
barecode. When such a barcode is read, POS adjusts the weight of the latest article in the order list.
The new weight is equal to the total weight minus the tare weight. The price is updated accordingly to the weight
change.

1
pos_barcode_tare/readme/USAGE.rst

@ -0,0 +1 @@
Install this add-on and configure the point of sale where you want to be able to use the tare barecode. You can also select the label format in the point of sale configuration. The label printing is done using web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or the kiosk printing (chrome).

BIN
pos_barcode_tare/static/description/icon.png

Before

Width: 1571  |  Height: 1690  |  Size: 90 KiB

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

443
pos_barcode_tare/static/description/index.html

@ -0,0 +1,443 @@
<?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 0.15.1: http://docutils.sourceforge.net/" />
<title>Point of Sale - Tare barecode labels for loose goods</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z 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
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="point-of-sale-tare-barecode-labels-for-loose-goods">
<h1 class="title">Point of Sale - Tare barecode labels for loose goods</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/pos/tree/9.0/pos_barcode_tare"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-9-0/pos-9-0-pos_barcode_tare"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/9.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This add-on enable POS to read and print tare barcodes. A tare barcode is used to sell loose goods in a bring your own
container (BYOC) scheme.</p>
<dl class="docutils">
<dt>The BYOC scheme has four steps:</dt>
<dd><ol class="first last arabic simple">
<li>The cashier weights the container and sticks the tare bar code onto the customer’s container.</li>
<li>The customer takes the desired quantity of the good s-he wants to buy.</li>
<li>The cashier weights the filled container and good, POS gives the corresponding price.</li>
<li>The cashier scans the tare bar code, POS removes the container’s weight from the latest product of the order.</li>
</ol>
</dd>
</dl>
<p>This add-on adds a news screen to POS to (web) print the tare barcode labels. This add-on enables POS to read a tare
barecode. When such a barcode is read, POS adjusts the weight of the latest article in the order list.
The new weight is equal to the total weight minus the tare weight. The price is updated accordingly to the weight
change.</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>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>Install this add-on and configure the point of sale where you want to be able to use the tare barecode.
You can also select the label format in the point of sale configuration. The label printing is done using
web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or
the kiosk printing (chrome).</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pos/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
<a class="reference external" href="https://github.com/OCA/pos/issues/new?body=module:%20pos_barcode_tare%0Aversion:%209.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>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Le Nid</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Le Nid</li>
<li>CoopITEasy</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">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
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/9.0/pos_barcode_tare">OCA/pos</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>
</div>
</body>
</html>

20
pos_barcode_tare/static/src/css/tare_screen.css → pos_barcode_tare/static/src/css/pos_barcode_tare.css

@ -20,6 +20,10 @@
overflow: hidden;
}
.pos .pos-tare-label .caption {
display: block;
}
.pos .tare-screen .pos-directions-for-user {
font-size: 25px;
margin: 8px;
@ -73,13 +77,16 @@
border: none;
}
.pos .pos-tare-label .caption {
display: block;
}
.pos .pos-tare-paper {
margin: 0;
margin-left: 0 !important;
margin-right: 0 !important;
width: 42mm !important;
height: 29mm !important;
background: white;
width: 99% !important;
height: 99% !important;
display: block;
position: fixed;
display: flex !important;
@ -87,10 +94,10 @@
align-items: center !important;
}
.pos-tare-label img {
width: 30mm !important;
height: 25mm !important;
width: 27mm !important;
height: 21mm !important;
display: run-in;
}
.pos .pos-tare-label {
@ -100,6 +107,5 @@
position: fixed !important;
border: none !important;
font-size: 10px !important;
}
}

36
pos_barcode_tare/static/src/js/barcode.js

@ -1,36 +0,0 @@
odoo.define('barcode_tare',function(require) {
"use strict";
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
var core = require('web.core');
var _t = core._t;
screens.ScreenWidget.include(
{
barcode_weight_action: function(code){
var self = this;
var order = this.pos.get_order();
var last_order_line = order.get_last_orderline();
var total_weight = last_order_line.get_quantity();
var tare = code.value;
var paid_weight = total_weight - tare;
if (paid_weight <= 0) {
this.gui.show_popup('confirm', {
'title': _t('Poids négatif'),
'body': _t('Le poids à payer est négatif. Avez-vous scanné le bon code bare ?'),
confirm: function(){
last_order_line.set_quantity(paid_weight)
}});
} else {
last_order_line.set_quantity(paid_weight)
}
},
show: function(){
var self = this;
this._super()
this.pos.barcode_reader.set_action_callback('weight', _.bind(self.barcode_weight_action, self))
},
});
});

20
pos_barcode_tare/static/src/js/open_tare_screen_button.js

@ -1,20 +0,0 @@
odoo.define('tare-screen-button.button', function (require) {
"use strict";
var core = require('web.core');
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
var TareScreenButton = screens.ActionButtonWidget.extend({
template: 'TareScreenButton',
button_click: function(){
var self = this;
this.gui.show_screen('tare');
}
});
screens.define_action_button({
'name': 'tareScreenButton',
'widget': TareScreenButton,
});
});

199
pos_barcode_tare/static/src/js/pos_barcode_tare.js

@ -0,0 +1,199 @@
odoo.define('barcode_tare', function (require) {
"use strict";
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
var core = require('web.core');
var _t = core._t;
screens.ScreenWidget.include(
{
barcode_weight_action: function (code) {
var self = this;
var order = this.pos.get_order();
var last_order_line = order.get_last_orderline();
var total_weight = last_order_line.get_quantity();
var tare = code.value;
var paid_weight = total_weight - tare;
if (paid_weight <= 0) {
self.gui.show_popup('confirm',
{'title': _t('Negative weight'),
'body': _t('The calculated weight is negative. ' +
'Did you scan the correct tare label?'),
confirm: function () {
last_order_line.set_quantity(paid_weight);
}});
} else {
last_order_line.set_quantity(paid_weight);
}
},
show: function () {
var self = this;
this._super();
this.pos.barcode_reader.set_action_callback(
'weight',
_.bind(self.barcode_weight_action, self));
},
});
});
odoo.define('tare-screen-button.button', function (require) {
"use strict";
var core = require('web.core');
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
var TareScreenButton = screens.ActionButtonWidget.extend({
template: 'TareScreenButton',
button_click: function () {
var self = this;
this.gui.show_screen('tare');
},
});
screens.define_action_button({
'name': 'tareScreenButton',
'widget': TareScreenButton,
});
});
odoo.define('tare-screen.screen', function (require) {
"use strict";
var chrome = require('point_of_sale.chrome');
var core = require('web.core');
var devices = require('point_of_sale.devices');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var QWeb = core.qweb;
var TareScreenWidget = screens.ScreenWidget.extend({
template: 'TareScreenWidget',
next_screen: 'products',
previous_screen: 'products',
default_tare_value_kg: 0.0,
show: function () {
this._super();
var self = this;
var queue = this.pos.proxy_queue;
queue.schedule(function () {
return self.pos.proxy.scale_read().then(function (weight) {
self.set_weight(weight.weight);
});
}, {duration:150, repeat: true});
this.render_receipt();
this.lock_screen(true);
},
set_weight: function (weight) {
if (weight > 0) {
this.weight = weight;
this.render_receipt();
this.lock_screen(false);
}
},
get_weight: function () {
if (typeof this.weight === 'undefined') {
return this.default_tare_value_kg;
}
return this.weight;
},
ean13_checksum: function (s) {
var result = 0;
for (var counter = s.length-1; counter >=0; counter--) {
var counterCheckSum = counter % 2;
counterCheckSum *= 2;
counterCheckSum += 1;
result += parseInt(s.charAt(counter), 10) * counterCheckSum;
}
var checksum = 10;
checksum -= result % 10;
return checksum % 10;
},
barcode_data: function (weight) {
var padding_size = 5;
var default_weight_prefix_id = "21";
var void_product_id = '0'.repeat(padding_size);
var weight_in_gram = weight * 10e2;
var weight_with_padding = '0'.repeat(padding_size) + weight_in_gram;
var padded_weight = weight_with_padding.substr(
weight_with_padding.length - padding_size);
var barcode_data = default_weight_prefix_id.concat(void_product_id,
padded_weight);
var checksum = this.ean13_checksum(barcode_data);
var barcode = barcode_data.concat(checksum);
console.log(barcode);
return barcode;
},
get_barcode_data: function () {
return this.barcode_data(this.get_weight());
},
should_auto_print: function () {
return this.pos.config.iface_print_auto &&
!this.pos.get_order()._printed;
},
should_close_immediately: function () {
return this.pos.config.iface_print_via_proxy &&
this.pos.config.iface_print_skip_screen;
},
lock_screen: function (locked) {
this._locked = locked;
if (locked) {
this.$('.print-label').addClass('disabled');
} else {
this.$('.print-label').removeClass('disabled');
}
},
print_web: function () {
window.print();
this.pos.get_order()._printed = true;
},
print: function () {
var self = this;
// See comment in print function of ReceiptScreenWidget
this.lock_screen(true);
setTimeout(function () {
self.lock_screen(false);
}, 1000);
this.print_web();
this.click_back();
},
click_back: function () {
this.close();
this.gui.show_screen(this.previous_screen);
},
renderElement: function () {
var self = this;
this._super();
this.$('.back').click(function () {
self.click_back();
});
this.$('.print-label').click(function () {
if (!self._locked) {
self.print();
}
});
},
render_receipt: function () {
this.$('.pos-tare-label-container').html(
QWeb.render('PosTareLabel', {widget:this}));
},
close: function () {
this._super();
delete this.weight;
this.pos.proxy_queue.clear();
},
});
gui.define_screen({name:'tare', widget: TareScreenWidget});
});

139
pos_barcode_tare/static/src/js/tare_screen.js

@ -1,139 +0,0 @@
odoo.define('tare-screen.screen', function (require) {
"use strict";
var chrome = require('point_of_sale.chrome');
var core = require('web.core');
var devices = require('point_of_sale.devices');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var QWeb = core.qweb;
var TareScreenWidget = screens.ScreenWidget.extend({
template: 'TareScreenWidget',
next_screen: 'products',
previous_screen: 'products',
default_tare_value_kg: 0.0,
show: function(){
this._super();
var self = this;
var queue = this.pos.proxy_queue;
queue.schedule(function(){
return self.pos.proxy.scale_read().then(function(weight){
self.set_weight(weight.weight);
});
},{duration:150, repeat: true});
this.render_receipt();
this.lock_screen(true);
},
set_weight: function(weight){
if (weight > 0){
this.weight = weight;
this.render_receipt();
this.lock_screen(false);
}
},
get_weight: function(){
if (typeof this.weight === 'undefined') {
return this.default_tare_value_kg;
}
return this.weight;
},
ean13_checksum: function(s){
var result = 0;
for (let counter = s.length-1; counter >=0; counter--){
result = result + parseInt(s.charAt(counter)) * (1+(2*(counter % 2)));
}
return (10 - (result % 10)) % 10;
},
barcode_data: function(weight, weight_prefix_id=21){
var padding_size = 5;
var void_product_id = '0'.repeat(padding_size);
var weight_in_gram = weight * 10e2;
var weight_with_padding = '0'.repeat(padding_size) + weight_in_gram;
var padded_weight = weight_with_padding.substr(weight_with_padding.length - padding_size);
var barcode_data = `${weight_prefix_id}${void_product_id}${padded_weight}`;
var checksum = this.ean13_checksum(barcode_data);
console.log(`${barcode_data}${checksum}`);
return `${barcode_data}${checksum}`;
},
get_barcode_data: function(){
return this.barcode_data(this.get_weight());
},
should_auto_print: function() {
return this.pos.config.iface_print_auto && !this.pos.get_order()._printed;
},
should_close_immediately: function() {
return this.pos.config.iface_print_via_proxy && this.pos.config.iface_print_skip_screen;
},
lock_screen: function(locked) {
this._locked = locked;
if (locked) {
this.$('.print-label').addClass('disabled');
} else {
this.$('.print-label').removeClass('disabled');
}
},
print_web: function() {
window.print();
this.pos.get_order()._printed = true;
},
print: function() {
var self = this;
// The problem is that in chrome the print() is asynchronous and doesn't
// execute until all rpc are finished. So it conflicts with the rpc used
// to send the orders to the backend, and the user is able to go to the next
// screen before the printing dialog is opened. The problem is that what's
// printed is whatever is in the page when the dialog is opened and not when it's called,
// and so you end up printing the product list instead of the receipt...
//
// Fixing this would need a re-architecturing
// of the code to postpone sending of orders after printing.
//
// But since the print dialog also blocks the other asynchronous calls, the
// button enabling in the setTimeout() is blocked until the printing dialog is
// closed. But the timeout has to be big enough or else it doesn't work
// 1 seconds is the same as the default timeout for sending orders and so the dialog
// should have appeared before the timeout... so yeah that's not ultra reliable.
this.lock_screen(true);
setTimeout(function(){
self.lock_screen(false);
}, 1000);
this.print_web();
this.click_back();
},
click_back: function() {
this.close()
this.gui.show_screen(this.previous_screen);
},
renderElement: function() {
var self = this;
this._super();
this.$('.back').click(function(){
self.click_back();
});
this.$('.print-label').click(function(){
if (!self._locked) {
self.print();
}
});
},
render_receipt: function() {
this.$('.pos-tare-label-container').html(QWeb.render('PosTareLabel',{widget:this}));
},
close: function(){
this._super();
delete this.weight;
this.pos.proxy_queue.clear();
},
});
gui.define_screen({name:'tare', widget: TareScreenWidget});
});

9
pos_barcode_tare/static/src/xml/open_tare_screen_button.xml

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="TareScreenButton">
<span class="control-button">
<i class="fa fa-print"></i>
Créer une étiquette de tare
</span>
</t>
</templates>

19
pos_barcode_tare/static/src/xml/tare_screen.xml → pos_barcode_tare/static/src/xml/pos_barcode_tare.xml

@ -8,15 +8,15 @@
<i class='fa fa-angle-double-left'></i>
Back
</span>
<h1>Création d'une étiquette de tare</h1>
<h1>Print a tare label</h1>
</div>
<div class="centered-content">
<div class="pos-tare-label-container"></div>
<div class="pos-directions-for-user">
Appuyez sur la touche <span>print</span> puis vérifiez le poids ci-dessus.
Set the pot on the scale and check the weight above
</div>
<div class='print-label'>
Imprimer
Print
<i class='fa fa-angle-double-right'></i>
</div>
</div>
@ -29,10 +29,19 @@
<div class="pos-tare-paper">
<div class="pos-tare-label">
<img t-att-src="'/report/barcode/EAN13/' + widget.get_barcode_data()" />
<br />
tare = <t t-esc="widget.get_weight()" />kg
<span class="caption">tare = <t t-esc="widget.get_weight()" />kg</span>
</div>
</div>
</div>
</t>
<t t-name="TareScreenButton">
<t t-if="widget.pos.config.tare_label_button">
<span class="control-button">
<i class="fa fa-print"></i>
Print a tare label
</span>
</t>
</t>
</templates>

8
pos_barcode_tare/views/pos_barcode_tare.xml

@ -0,0 +1,8 @@
<odoo>
<template id="assets_backend" name="pos_barcode_tare" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_barcode_tare/static/src/css/pos_barcode_tare.css"/>
<script type="text/javascript" src="/pos_barcode_tare/static/src/js/pos_barcode_tare.js"></script>
</xpath>
</template>
</odoo>

16
pos_barcode_tare/views/pos_config_view.xml

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="view_pos_config_form">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form" />
<field name="arch" type="xml">
<xpath expr="/form/sheet/group[@name='features']" position="inside">
<separator string="Loose good options" colspan="4"/>
<group>
<field name="tare_label_button" />
</group>
</xpath>
</field>
</record>
</odoo>

12
pos_barcode_tare/views/templates.xml

@ -1,12 +0,0 @@
<odoo>
<data>
<template id="assets_backend" name="pos_barcode_tare" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_barcode_tare/static/src/css/tare_screen.css"/>
<script type="text/javascript" src="/pos_barcode_tare/static/src/js/tare_screen.js"></script>
<script type="text/javascript" src="/pos_barcode_tare/static/src/js/open_tare_screen_button.js"></script>
<script type="text/javascript" src="/pos_barcode_tare/static/src/js/barcode.js"></script>
</xpath>
</template>
</data>
</odoo>
Loading…
Cancel
Save