Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] pos_odoo_driver_device_list #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
1 change: 1 addition & 0 deletions pos_odoo_driver_device_list/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions pos_odoo_driver_device_list/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Point of Sale - Devices List (odoo-pos-driver)",
"version": "16.0.1.0.0",
"category": "Point Of Sale",
"summary": "Get devices information from odoo-pos-driver library",
"author": "GRAP",
"website": "https://github.com/grap/odoo-addons-pos",
"license": "AGPL-3",
"depends": ["point_of_sale"],
"assets": {
"point_of_sale.assets": [
"pos_odoo_driver_device_list/static/src/js/devices.esm.js",
],
},
"data": [
"security/ir.model.access.csv",
"security/ir_rule.xml",
"views/view_pos_device.xml",
],
"installable": True,
}
141 changes: 141 additions & 0 deletions pos_odoo_driver_device_list/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_odoo_driver_device_list
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-14 13:15+0000\n"
"PO-Revision-Date: 2024-09-14 13:15+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__company_id
msgid "Company"
msgstr "Société"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__config_id
msgid "Config"
msgstr "Point de vente"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__create_uid
msgid "Created by"
msgstr "Créé par"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__create_date
msgid "Created on"
msgstr "Créé le"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields.selection,name:pos_odoo_driver_device_list.selection__pos_device__device_type__display
msgid "Customer Display"
msgstr "Afficheur client"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_config__device_ids
msgid "Device"
msgstr "Périphérique"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__device_type
msgid "Device Type"
msgstr "Type de périphérique"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__display_name
msgid "Display Name"
msgstr "Nom complet"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__id
msgid "ID"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__last_connexion_date
msgid "Last Connexion Date"
msgstr "Date de dernière connexion"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device____last_update
msgid "Last Modified on"
msgstr "Dernière mise à jour le"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__write_uid
msgid "Last Updated by"
msgstr "Dernière mise à jour par"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__manufacturer
msgid "Manufacturer"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__name
msgid "Name"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields.selection,name:pos_odoo_driver_device_list.selection__pos_device__device_type__payment
msgid "Payment Terminal"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.ui.menu,name:pos_odoo_driver_device_list.menu_pos_device
msgid "PoS Devices"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model,name:pos_odoo_driver_device_list.model_pos_config
msgid "Point of Sale Configuration"
msgstr "Configuration du point de vente"

#. module: pos_odoo_driver_device_list
#: model:ir.model,name:pos_odoo_driver_device_list.model_pos_device
msgid "Point of Sale Devices"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.actions.act_window,name:pos_odoo_driver_device_list.action_pos_device
msgid "Pos Devices"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields.selection,name:pos_odoo_driver_device_list.selection__pos_device__device_type__printer
msgid "Printer"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__product_name
msgid "Product Name"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields.selection,name:pos_odoo_driver_device_list.selection__pos_device__device_type__scale
msgid "Scale"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__serial_number
msgid "Serial Number"
msgstr ""

#. module: pos_odoo_driver_device_list
#: model:ir.model.fields,field_description:pos_odoo_driver_device_list.field_pos_device__vendor_product_code
msgid "Vendor Product Code"
msgstr ""
2 changes: 2 additions & 0 deletions pos_odoo_driver_device_list/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import pos_config
from . import pos_device
53 changes: 53 additions & 0 deletions pos_odoo_driver_device_list/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import datetime

from odoo import api, fields, models


class PosConfig(models.Model):
_inherit = "pos.config"

device_ids = fields.One2many(comodel_name="pos.device", inverse_name="config_id")

@api.model
def update_pos_device(self, config_id, changes):
PosDevice = self.env["pos.device"]

Check warning on line 17 in pos_odoo_driver_device_list/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_config.py#L17

Added line #L17 was not covered by tests
for device_type, device_info in changes.items():
existing_device = PosDevice.search(

Check warning on line 19 in pos_odoo_driver_device_list/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_config.py#L19

Added line #L19 was not covered by tests
[
("config_id", "=", config_id),
("device_type", "=", device_type),
("name", "=", device_info.get("device_name", False)),
("product_name", "=", device_info.get("product_name", False)),
("manufacturer", "=", device_info.get("manufacturer", False)),
("serial_number", "=", device_info.get("serial_number", False)),
(
"vendor_product_code",
"=",
device_info.get("vendor_product_code", False),
),
],
limit=1,
order="last_connexion_date desc",
)
if existing_device:
existing_device.write({"last_connexion_date": datetime.now()})

Check warning on line 37 in pos_odoo_driver_device_list/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_config.py#L37

Added line #L37 was not covered by tests
else:
PosDevice.create(

Check warning on line 39 in pos_odoo_driver_device_list/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_config.py#L39

Added line #L39 was not covered by tests
{
"config_id": config_id,
"device_type": device_type,
"name": device_info.get("device_name", False),
"product_name": device_info.get("product_name", False),
"manufacturer": device_info.get("manufacturer", False),
"serial_number": device_info.get("serial_number", False),
"vendor_product_code": device_info.get(
"vendor_product_code", False
),
"last_connexion_date": datetime.now(),
}
)
return True

Check warning on line 53 in pos_odoo_driver_device_list/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_config.py#L53

Added line #L53 was not covered by tests
39 changes: 39 additions & 0 deletions pos_odoo_driver_device_list/models/pos_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class PosDevice(models.Model):
_name = "pos.device"
_description = "Point of Sale Devices"
_order = "last_connexion_date desc, name"

device_type = fields.Selection(
selection=[
("display", "Customer Display"),
("payment", "Payment Terminal"),
("scale", "Scale"),
("printer", "Printer"),
]
)

config_id = fields.Many2one(comodel_name="pos.config")

company_id = fields.Many2one(related="config_id.company_id")

name = fields.Char(readonly=True)

product_name = fields.Char(readonly=True)

vendor_product_code = fields.Char(readonly=True)

serial_number = fields.Char(readonly=True)

manufacturer = fields.Char(readonly=True)

last_connexion_date = fields.Datetime(readonly=True)

def _default_company_id(self):
return self.env.company

Check warning on line 39 in pos_odoo_driver_device_list/models/pos_device.py

View check run for this annotation

Codecov / codecov/patch

pos_odoo_driver_device_list/models/pos_device.py#L39

Added line #L39 was not covered by tests
1 change: 1 addition & 0 deletions pos_odoo_driver_device_list/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
4 changes: 4 additions & 0 deletions pos_odoo_driver_device_list/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module extends the Point of Sale odoo module, to add compatibility
with the ``odoo-pos-driver`` python library.

It will store connected devices information in Odoo for analysis.
9 changes: 9 additions & 0 deletions pos_odoo_driver_device_list/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* Open the Point of sale, with usb devices connected.

* Close the point of sale.

* Go to " / Devices".

you can see the devices information, with last usage date.

.. figure:: ../static/img/pos_device_tree.png
3 changes: 3 additions & 0 deletions pos_odoo_driver_device_list/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_pos_device_user,access_pos_device_user,pos_odoo_driver_device_list.model_pos_device,point_of_sale.group_pos_user,1,1,1,0
access_pos_device_manager,access_pos_device_manager,pos_odoo_driver_device_list.model_pos_device,base.group_system,1,1,1,1
19 changes: 19 additions & 0 deletions pos_odoo_driver_device_list/security/ir_rule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2024-Today GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="rule_pos_device" model="ir.rule">
<field name="name">PoS Device Rule</field>
<field
name="model_id"
ref="pos_odoo_driver_device_list.model_pos_device"
/>
<field name="global" eval="True" />
<field name="domain_force">[('company_id', 'in', company_ids + [False])]</field>
</record>

</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions pos_odoo_driver_device_list/static/src/js/devices.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
// @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

odoo.define("pos_odoo_driver_device_list.devices", function (require) {

var ProxyDevice = require("point_of_sale.devices").ProxyDevice;

var set_connection_status_super = ProxyDevice.prototype.set_connection_status;

ProxyDevice.prototype.set_connection_status = function (status, drivers, msg='') {
if (status === 'connected' && drivers !== undefined) {
var old_drivers = this.get('status').drivers;
var changes = {};
Object.entries(drivers).forEach(([driver_name, driver_value]) => {
if (driver_value.status === "connected") {
if (JSON.stringify(driver_value) !== JSON.stringify(old_drivers[driver_name])) {
changes[driver_name] = driver_value;
}
}
})
if (Object.keys(changes).length !== 0) {
this.env.services.rpc({
model: 'pos.config',
method: 'update_pos_device',
args: [this.env.pos.config.id, changes],
kwargs: {context: this.env.session.user_context},
}, {})
.then(function (result) {
console.log("THEN: ", result)
}).catch(function (error){
console.warn('catch: ', error);
});

console.log("CHANGES: ", changes)
}
}
set_connection_status_super.call(this, status, drivers, msg);
};

});
39 changes: 39 additions & 0 deletions pos_odoo_driver_device_list/views/view_pos_device.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" ?>
<!--
Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="view_pos_device_tree" model="ir.ui.view">
<field name="model">pos.device</field>
<field name="arch" type="xml">
<tree>
<field name="last_connexion_date"/>
<field name="name"/>
<field name="device_type"/>
<field name="vendor_product_code" optional="show"/>
<field name="serial_number" optional="show"/>
<field name="manufacturer" optional="hide"/>
<field name="product_name" optional="hide"/>
<field name="config_id" optional="show"/>
<field name="company_id" optional="hide" groups="base.group_multi_company"/>
</tree>
</field>
</record>

<record id="action_pos_device" model="ir.actions.act_window">
<field name="name">Pos Devices</field>
<field name="res_model">pos.device</field>
<field name="view_mode">tree</field>
</record>

<record id="menu_pos_device" model="ir.ui.menu">
<field name="name">PoS Devices</field>
<field name="sequence" eval="20" />
<field name="action" ref="action_pos_device" />
<field name="parent_id" ref="point_of_sale.menu_point_config_product" />
</record>

</odoo>
2 changes: 2 additions & 0 deletions setup/.setuptools-odoo-make-default-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)
2 changes: 2 additions & 0 deletions setup/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo
Loading
Loading