summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/models/product.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/models/product.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/point_of_sale/models/product.py')
-rw-r--r--addons/point_of_sale/models/product.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/addons/point_of_sale/models/product.py b/addons/point_of_sale/models/product.py
new file mode 100644
index 00000000..b367c766
--- /dev/null
+++ b/addons/point_of_sale/models/product.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import api, fields, models, _
+from odoo.exceptions import UserError
+
+
+class ProductTemplate(models.Model):
+ _inherit = 'product.template'
+
+ available_in_pos = fields.Boolean(string='Available in POS', help='Check if you want this product to appear in the Point of Sale.', default=False)
+ to_weight = fields.Boolean(string='To Weigh With Scale', help="Check if the product should be weighted using the hardware scale integration.")
+ pos_categ_id = fields.Many2one(
+ 'pos.category', string='Point of Sale Category',
+ help="Category used in the Point of Sale.")
+
+ def unlink(self):
+ product_ctx = dict(self.env.context or {}, active_test=False)
+ if self.with_context(product_ctx).search_count([('id', 'in', self.ids), ('available_in_pos', '=', True)]):
+ if self.env['pos.session'].sudo().search_count([('state', '!=', 'closed')]):
+ raise UserError(_('You cannot delete a product saleable in point of sale while a session is still opened.'))
+ return super(ProductTemplate, self).unlink()
+
+ @api.onchange('sale_ok')
+ def _onchange_sale_ok(self):
+ if not self.sale_ok:
+ self.available_in_pos = False
+
+
+class ProductProduct(models.Model):
+ _inherit = 'product.product'
+
+ def unlink(self):
+ product_ctx = dict(self.env.context or {}, active_test=False)
+ if self.env['pos.session'].sudo().search_count([('state', '!=', 'closed')]):
+ if self.with_context(product_ctx).search_count([('id', 'in', self.ids), ('product_tmpl_id.available_in_pos', '=', True)]):
+ raise UserError(_('You cannot delete a product saleable in point of sale while a session is still opened.'))
+ return super(ProductProduct, self).unlink()
+
+
+class UomCateg(models.Model):
+ _inherit = 'uom.category'
+
+ is_pos_groupable = fields.Boolean(string='Group Products in POS',
+ help="Check if you want to group products of this category in point of sale orders")
+
+
+class Uom(models.Model):
+ _inherit = 'uom.uom'
+
+ is_pos_groupable = fields.Boolean(related='category_id.is_pos_groupable', readonly=False)