Skip to content

Commit

Permalink
Merge PR #861 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Jul 17, 2023
2 parents 2507767 + 545d82d commit ce5506e
Show file tree
Hide file tree
Showing 29 changed files with 501 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions pos_membership_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
33 changes: 33 additions & 0 deletions pos_membership_extension/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2022-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Point of Sale - Membership Extension",
"summary": "Prevent to sale product in the point of sale"
" to customer that don't belong to membership categories",
"version": "16.0.1.0.0",
"category": "Point of Sale",
"maintainers": ["legalsylvain"],
"author": "GRAP,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": ["point_of_sale", "membership_extension"],
"assets": {
"point_of_sale.assets": [
"pos_membership_extension/static/src/css/pos.css",
"pos_membership_extension/static/src/js/ProductItem.js",
"pos_membership_extension/static/src/js/ProductScreen.js",
"pos_membership_extension/static/src/js/models.js",
"pos_membership_extension/static/src/xml/ProductItem.xml",
"pos_membership_extension/static/src/xml/ProductInfoPopup.xml",
],
},
"data": [
"views/view_product_template.xml",
],
"demo": [
"demo/product_product.xml",
],
"installable": True,
}
16 changes: 16 additions & 0 deletions pos_membership_extension/demo/product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2022-Today GRAP (http://www.grap.coop)
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
-->
<odoo>
<record id="product_for_member" model="product.product">
<field name="name">Product for Member</field>
<field name="available_in_pos" eval="True" />
<field
name="allowed_membership_category_ids"
eval="[(4, ref('membership_extension.membership_category_member'))]"
/>
</record>
</odoo>
103 changes: 103 additions & 0 deletions pos_membership_extension/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_membership_extension
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.5alpha1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-08 16:06+0000\n"
"PO-Revision-Date: 2022-09-08 16:06+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_membership_extension
#: model:ir.model.fields,field_description:pos_membership_extension.field_product_product__allowed_membership_category_ids
#: model:ir.model.fields,field_description:pos_membership_extension.field_product_template__allowed_membership_category_ids
msgid "Allowed Membership categories"
msgstr "Catégories d'adhésions authorisées"

#. module: pos_membership_extension
#: model:ir.model.fields,help:pos_membership_extension.field_product_product__allowed_membership_category_ids
#: model:ir.model.fields,help:pos_membership_extension.field_product_template__allowed_membership_category_ids
msgid ""
"If set, the product will be sallable only to customer that belong to the "
"given membership categories"
msgstr "Si défini, le produit ne pourra être vendu qu'à des clients qui appartiennent aux catégories d'adhésions définies ici."

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/js/ProductScreen.js:0
#, python-format
msgid "Incorrect Membership"
msgstr "Adhésion incorrecte"

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/xml/ProductInfoPopup.xml:0
#, python-format
msgid "Membership Categories:"
msgstr "Catégories d'adhésions : "

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/js/models.js:0
#, python-format
msgid "Order Line Removal"
msgstr "Retrait d'une ligne de vente"

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/js/ProductScreen.js:0
#, python-format
msgid ""
"Please select a customer that belong to one of the related membership "
"categories."
msgstr "Veuillez sélectionner un client qui appartient à l'une des catégories d'adhésions."

#. module: pos_membership_extension
#: model:ir.model,name:pos_membership_extension.model_pos_session
msgid "Point of Sale Session"
msgstr "Session du point de vente"

#. module: pos_membership_extension
#: model:ir.model,name:pos_membership_extension.model_product_template
msgid "Product"
msgstr ""

#. module: pos_membership_extension
#: model:ir.model,name:pos_membership_extension.model_product_product
msgid "Product Variant"
msgstr ""

#. module: pos_membership_extension
#: model:product.product,name:pos_membership_extension.product_for_member
#: model:product.template,name:pos_membership_extension.product_for_member_product_template
msgid "Product for Member"
msgstr ""

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/js/models.js:0
#, python-format
msgid ""
"The sale line of product '' has been removed, as it cannot be sold to this "
"partner."
msgstr "La ligne de vente du produit '' a été retirée, car elle ne peux pas être vendu à ce client."

#. module: pos_membership_extension
#. openerp-web
#: code:addons/pos_membership_extension/static/src/xml/ProductItem.xml:0
#, python-format
msgid "This product can not be sold because of membership rules"
msgstr "Ce produit ne peut pas être vendu à cause de règles liées à l'adhésion."

#. module: pos_membership_extension
#: model:product.product,uom_name:pos_membership_extension.product_for_member
#: model:product.template,uom_name:pos_membership_extension.product_for_member_product_template
msgid "Units"
msgstr ""
3 changes: 3 additions & 0 deletions pos_membership_extension/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pos_session
from . import product_product
from . import product_template
32 changes: 32 additions & 0 deletions pos_membership_extension/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2022-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models


class PosSession(models.Model):
_inherit = "pos.session"

def _loader_params_product_product(self):
res = super()._loader_params_product_product()
res["search_params"]["fields"] += ["allowed_membership_category_ids"]
return res

def _loader_params_res_partner(self):
res = super()._loader_params_res_partner()
res["search_params"]["fields"] += ["membership_category_ids"]
return res

def _pos_ui_models_to_load(self):
result = super()._pos_ui_models_to_load()
result.append("membership.membership_category")
return result

def _loader_params_membership_membership_category(self):
return {"search_params": {"domain": [], "fields": []}}

def _get_pos_ui_membership_membership_category(self, params):
return self.env["membership.membership_category"].search_read(
**params["search_params"]
)
18 changes: 18 additions & 0 deletions pos_membership_extension/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2022-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models


class ProductProduct(models.Model):
_inherit = "product.product"

def get_product_info_pos(self, price, quantity, pos_config_id):
res = super().get_product_info_pos(price, quantity, pos_config_id)

res["allowed_membership_categories"] = [
{"name": category.name} for category in self.allowed_membership_category_ids
]

return res
16 changes: 16 additions & 0 deletions pos_membership_extension/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2022-Today GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

allowed_membership_category_ids = fields.Many2many(
string="Allowed Membership categories",
comodel_name="membership.membership_category",
help="If set, the product will be sallable only to customer"
" that belong to the given membership categories",
)
8 changes: 8 additions & 0 deletions pos_membership_extension/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* open a product form
* Go to the sale tab
* fill the field "Allowed Membership Categories"

.. figure:: ../static/description/product_form.png

* Configure also the membership categories. For that purpose, refer
to the documentation of the OCA ``membership_extension`` module.
1 change: 1 addition & 0 deletions pos_membership_extension/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
3 changes: 3 additions & 0 deletions pos_membership_extension/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* UGESS, Union Nationale des Groupements des épiceries Sociales et Solidaires (https://ugess.org/)
5 changes: 5 additions & 0 deletions pos_membership_extension/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module extends the functionality of point of sale module to implement
features related to ``membership_extension`` OCA module.
(https://github.com/OCA/vertical-association repository)
For the time being, it prevents cashier to sell product to customer
that doesn't belong to some membership categories.
3 changes: 3 additions & 0 deletions pos_membership_extension/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* If OCA members want to develop a module named ``sale_membership_extension``
we should extract move some part of the code of the current module in the new module
and make the current module depends on the new one.
24 changes: 24 additions & 0 deletions pos_membership_extension/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* open the Point of Sale product

* You can see that some products have a new icon that mention
that the product is not sallable. the icon disappear if you select
a customer that belong to one of the membership categories :

.. figure:: ../static/description/point_of_sale_product_item.png

* The module adds in the Product Pop Up info, the list of the membership categories
allowed for the current product :

.. figure:: ../static/description/point_of_sale_popup_product_info.png

* If you select the product with an incorrect customer,
you'll see an error Popup :

.. figure:: ../static/description/point_of_sale_popup_error.png

* If you selected allowed restricted product for a partner, and then switch
for another partner, a check is realized to verify that the selected products
are allowed. If not, order lines will be removed and a popup message
will be displayed :

.. figure:: ../static/description/point_of_sale_switch_partner_popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions pos_membership_extension/static/src/css/pos.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (C) 2022-Today GRAP (http://www.grap.coop)
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
*/

.pos .product .membership-forbidden-tag {
color: white;
background: rgba(255, 76, 76, 0.5);
border-radius: 2px;
padding: 1px 4px;
}

.product-info-popup .allowed-membership-category {
display: inline-block;
max-width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: top;
max-width: 200px;
color: inherit;
line-height: 1.1;
}
22 changes: 22 additions & 0 deletions pos_membership_extension/static/src/js/ProductItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
odoo.define("pos_membership_extension.ProductItem", function (require) {
"use strict";

const ProductItem = require("point_of_sale.ProductItem");
const Registries = require("point_of_sale.Registries");

// eslint-disable-next-line no-shadow
const OverloadProductItem = (ProductItem) =>
// eslint-disable-next-line no-shadow
class OverloadProductItem extends ProductItem {
get membership_allowed() {
var res = this.props.product.get_membership_allowed(
this.env.pos.get_order().partner
);
return res;
}
};

Registries.Component.extend(ProductItem, OverloadProductItem);

return ProductItem;
});
29 changes: 29 additions & 0 deletions pos_membership_extension/static/src/js/ProductScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
odoo.define("pos_membership_extension.ProductScreen", function (require) {
"use strict";

const ProductScreen = require("point_of_sale.ProductScreen");
const Registries = require("point_of_sale.Registries");

// eslint-disable-next-line no-shadow
const OverloadProductScreen = (ProductScreen) =>
// eslint-disable-next-line no-shadow
class OverloadProductScreen extends ProductScreen {
async _getAddProductOptions(product) {
var self = this;
if (!product.get_membership_allowed(this.env.pos.get_order().partner)) {
await this.showPopup("ErrorPopup", {
title: self.env._t("Incorrect Membership"),
body: self.env._t(
"Please select a customer that belong to one of the related membership categories."
),
});
return;
}
return await super._getAddProductOptions(...arguments);
}
};

Registries.Component.extend(ProductScreen, OverloadProductScreen);

return ProductScreen;
});
Loading

0 comments on commit ce5506e

Please sign in to comment.