Browse Source

[ADD] pos_require_product_quantity

pull/490/head
robin.keunen 6 years ago
committed by Manuel Claeys Bouuaert
parent
commit
c4772cac07
  1. 1
      pos_require_product_quantity/__init__.py
  2. 24
      pos_require_product_quantity/__openerp__.py
  3. 1
      pos_require_product_quantity/models/__init__.py
  4. 15
      pos_require_product_quantity/models/pos_config.py
  5. 59
      pos_require_product_quantity/static/src/js/pos.js
  6. 12
      pos_require_product_quantity/static/src/xml/templates.xml
  7. 15
      pos_require_product_quantity/views/pos_config.xml

1
pos_require_product_quantity/__init__.py

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

24
pos_require_product_quantity/__openerp__.py

@ -0,0 +1,24 @@
# coding: utf-8
# Copyright 2019 Coop IT Easy SCRLfs
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Require Product Quantity in POS",
"version": "9.0.0.1.0",
"author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)",
"website": "www.coopiteasy.be",
"license": "AGPL-3",
"category": "Point of Sale",
"summary": """
A popup is shown if product quantity is set to 0 for one or more order
lines when clicking on "Payment" button.
""",
"depends": [
'point_of_sale',
],
'data': [
'views/pos_config.xml',
'static/src/xml/templates.xml',
],
'installable': True,
}

1
pos_require_product_quantity/models/__init__.py

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

15
pos_require_product_quantity/models/pos_config.py

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# © 2016 Robin Keunen, Coop IT Easy SCRL fs
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
require_product_quantity = fields.Boolean(
string='Require product quantity in POS',
default=False,
)

59
pos_require_product_quantity/static/src/js/pos.js

@ -0,0 +1,59 @@
/*
Copyright 2019 Coop IT Easy SCRLfs
Robin Keunen <robin@coopiteasy.be>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define(
'pos_require_product_quantity.pos_require_product_quantity',
function (require) {
"use strict";
var core = require('web.core');
var screens = require("point_of_sale.screens");
var _t = core._t;
screens.ActionpadWidget = screens.ActionpadWidget.include({
renderElement: function () {
var self = this;
this._super();
this.$('.pay').click(function () {
if (self.pos.config.require_product_quantity) {
var orderlines = self.pos.get_order().orderlines;
var qty_unset_list = [];
for (var i = 0; i < orderlines.length; i++) {
var line = orderlines.models[i];
if (line.quantity === 0) {
qty_unset_list.push(line);
}
}
if (qty_unset_list.length > 0) {
self.gui.back();
var body = _t('No quantity set for products:');
for (var j = 0; j < qty_unset_list.length; j++) {
body = (
body
+ ' - '
+ qty_unset_list[j].product.display_name
);
}
self.gui.show_popup(
'alert',
{
'title': _t('Missing quantities'),
'body': body,
},
);
}
}
});
}
})
}
);

12
pos_require_product_quantity/static/src/xml/templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="pos_require_product_quantity_extension_assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/pos_require_product_quantity/static/src/js/pos.js">
</script>
</xpath>
</template>
</data>
</odoo>

15
pos_require_product_quantity/views/pos_config.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<odoo>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="name">pos.config.form.view.inherit</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="arch" type="xml">
<field name="tip_product_id" position="after">
<field name="require_product_quantity"/>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save