-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
[14.0][IMP] pos_disable_pricelist_selection: selectable pricelists #1110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,76 @@ | ||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class PosConfig(models.Model): | ||
_inherit = "pos.config" | ||
|
||
def _default_pricelist(self): | ||
return self.env["product.pricelist"].search( | ||
[ | ||
("company_id", "in", (False, self.env.company.id)), | ||
("currency_id", "=", self.env.company.currency_id.id), | ||
], | ||
limit=1, | ||
) | ||
|
||
hide_pricelist_button = fields.Boolean( | ||
default=False, | ||
) | ||
selectable_pricelist_ids = fields.Many2many( | ||
"product.pricelist", | ||
string="Selectable Pricelists", | ||
domain="[('id', 'in', available_pricelist_ids)]", | ||
relation="pos_conf_selectable_pricelist_rel", | ||
default=_default_pricelist, | ||
) | ||
pricelist_id_domain = fields.Binary( | ||
compute="_compute_pricelist_id_domain", | ||
readonly=True, | ||
store=False, | ||
) | ||
|
||
@api.depends( | ||
"hide_pricelist_button", "allowed_pricelist_ids", "selectable_pricelist_ids" | ||
) | ||
def _compute_pricelist_id_domain(self): | ||
for rec in self: | ||
if rec.hide_pricelist_button: | ||
rec.pricelist_id_domain = [("id", "in", rec.allowed_pricelist_ids.ids)] | ||
else: | ||
rec.pricelist_id_domain = [ | ||
("id", "in", rec.selectable_pricelist_ids.ids) | ||
] | ||
Comment on lines
+37
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: Documentation of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't find a way to cause an error, so considering this non-blocking. |
||
|
||
@api.onchange("selectable_pricelist_ids") | ||
def onchange_selectable_pricelist_ids(self): | ||
if self.pricelist_id.id not in self.selectable_pricelist_ids.ids: | ||
self.update({"pricelist_id": self.selectable_pricelist_ids[0].id}) | ||
|
||
@api.onchange("available_pricelist_ids") | ||
def onchange_available_pricelist_ids(self): | ||
self.update( | ||
{"selectable_pricelist_ids": [(6, 0, self.allowed_pricelist_ids.ids)]} | ||
) | ||
|
||
@api.onchange("hide_pricelist_button") | ||
def onchange_hide_pricelist_button(self): | ||
self.update( | ||
{"selectable_pricelist_ids": [(6, 0, self.allowed_pricelist_ids.ids)]} | ||
) | ||
|
||
def write(self, vals): | ||
for rec in self: | ||
if vals.get("available_pricelist_ids"): | ||
if rec and not vals.get("selectable_pricelist_ids"): | ||
selectable = set(rec.selectable_pricelist_ids.ids) | ||
else: | ||
selectable = set(vals["selectable_pricelist_ids"][0][2]) | ||
# leave only ids from available_pricelist_ids | ||
intersection = list( | ||
selectable.intersection(set(vals["available_pricelist_ids"][0][2])) | ||
) | ||
if intersection: | ||
vals["selectable_pricelist_ids"] = [(6, 0, intersection)] | ||
else: | ||
vals["selectable_pricelist_ids"] = vals["available_pricelist_ids"] | ||
return super(PosConfig, self).write(vals) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
In case there is a structure of pricelists with lines using "Formula: Based on" (eg: Pricelist 3 is based on Pricelist 2 which is based on Pricelist 1) they all need to be added in "Available pricelists" for POS to load correctly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Disable Pricelist selection button in POS | ||
This module allows to restrict POS interface user from selecting any or specific pricelists. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
* In POS configuration enable multiple pricelists | ||
* There will be a checkbox "Hide Pricelist Button" | ||
* If checked pricelist selection button will be hidden in POS Screen | ||
In POS configuration, enable advanced pricelists and add all pricelists with reference to pricelists to be used in POS in "Available Pricelists". | ||
|
||
To restrict POS user from selecting any pricelist (therefore only use prices from "Default Pricelist"), enable boolean "Hide Pricelist Button" | ||
|
||
To restrict POS user's pricelist selection to a set of pricelists, add them to "Selectable Pricelists". | ||
Note: make sure "Default Pricelist" is among "Selectable Pricelists". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
odoo.define("pos_disable_pricelist_selection.PosModel", function (require) { | ||
"use strict"; | ||
|
||
var models = require("point_of_sale.models"); | ||
var posmodel_super = models.PosModel.prototype; | ||
|
||
models.PosModel = models.PosModel.extend({ | ||
load_server_data: function () { | ||
this.models.push({ | ||
model: "product.pricelist", | ||
fields: ["name", "display_name", "discount_policy"], | ||
domain: function (self) { | ||
if (self.config.use_pricelist) { | ||
if (self.config.hide_pricelist_button) { | ||
return [["id", "in", self.config.available_pricelist_ids]]; | ||
} | ||
return [["id", "in", self.config.selectable_pricelist_ids]]; | ||
} | ||
return [["id", "=", self.config.pricelist_id[0]]]; | ||
}, | ||
loaded: function (self, pricelists) { | ||
_.map(pricelists, function (pricelist) { | ||
pricelist.items = []; | ||
}); | ||
self.selectable_pricelists = pricelists; | ||
}, | ||
}); | ||
return posmodel_super.load_server_data.apply(this, arguments); | ||
}, | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
odoo.define("pos_disable_pricelist_selection.SetPricelistButton", function (require) { | ||
"use strict"; | ||
|
||
const SetPricelistButton = require("point_of_sale.SetPricelistButton"); | ||
const Registries = require("point_of_sale.Registries"); | ||
|
||
const SetPricelistButtonSelect = (SetPricelistButton) => | ||
class extends SetPricelistButton { | ||
async onClick() { | ||
// Lets use selectable_pricelists instead of pricelists | ||
const original_pricelists = this.env.pos.pricelists; | ||
this.env.pos.pricelists = this.env.pos.selectable_pricelists; | ||
super.onClick(); | ||
this.env.pos.pricelists = original_pricelists; | ||
} | ||
}; | ||
|
||
Registries.Component.extend(SetPricelistButton, SetPricelistButtonSelect); | ||
|
||
return SetPricelistButtonSelect; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: missing dependency on
web_domain_field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
web_domain_field is not required. Turns out compute domain thing works without web_domain_field. Just need to use Binary field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that's good to know. Thanks!