You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							96 lines
						
					
					
						
							4.1 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							96 lines
						
					
					
						
							4.1 KiB
						
					
					
				
								# -*- coding: utf-8 -*-
							 | 
						|
								################################################################################
							 | 
						|
								#
							 | 
						|
								#    Cybrosys Technologies Pvt. Ltd.
							 | 
						|
								#
							 | 
						|
								#    Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
							 | 
						|
								#    Author: Megha K (odoo@cybrosys.com)
							 | 
						|
								#
							 | 
						|
								#    You can modify it under the terms of the GNU AFFERO
							 | 
						|
								#    GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
							 | 
						|
								#
							 | 
						|
								#    This program is distributed in the hope that it will be useful,
							 | 
						|
								#    but WITHOUT ANY WARRANTY; without even the implied warranty of
							 | 
						|
								#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
							 | 
						|
								#    GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
							 | 
						|
								#
							 | 
						|
								#    You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
							 | 
						|
								#    (AGPL v3) along with this program.
							 | 
						|
								#    If not, see <http://www.gnu.org/licenses/>.
							 | 
						|
								#
							 | 
						|
								################################################################################
							 | 
						|
								from odoo import api, fields, models, _
							 | 
						|
								from odoo.exceptions import ValidationError
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class PosCrossSelling(models.Model):
							 | 
						|
								    """Model Pos Cross-Selling Products"""
							 | 
						|
								    _name = 'pos.cross.selling'
							 | 
						|
								    _description = 'POS Cross-Selling'
							 | 
						|
								    _rec_name = 'product_id'
							 | 
						|
								
							 | 
						|
								    product_id = fields.Many2one('product.product',
							 | 
						|
								                                 domain=[('available_in_pos', '=', 'True')],
							 | 
						|
								                                 required=True, string='Product Name',
							 | 
						|
								                                 help="Product details")
							 | 
						|
								    active = fields.Boolean(string='Active',
							 | 
						|
								                            help="To check the cross selling is active or not",
							 | 
						|
								                            default=True)
							 | 
						|
								    pos_cross_product_ids = fields.One2many('pos.cross.selling.line',
							 | 
						|
								                                            'pos_cross_product_id',
							 | 
						|
								                                            string='Pos Cross products',
							 | 
						|
								                                            help="Pos Cross products")
							 | 
						|
								
							 | 
						|
								    @api.constrains('product_id')
							 | 
						|
								    def _check_product_id(self):
							 | 
						|
								        """This method for avoid multiple creation of pos
							 | 
						|
								         cross-selling products"""
							 | 
						|
								        for rec in self:
							 | 
						|
								            pos = self.env['pos.cross.selling'].search(
							 | 
						|
								                [('product_id', '=', rec.product_id.id)])
							 | 
						|
								            if len(pos) > 1:
							 | 
						|
								                raise ValidationError(_('Already exist a cross product with the'
							 | 
						|
								                                        ' %s product ') % rec.product_id.name)
							 | 
						|
								
							 | 
						|
								    @api.constrains('pos_cross_product_ids')
							 | 
						|
								    def _check_pos_cross_product_ids(self):
							 | 
						|
								        """This method for add cross product lines"""
							 | 
						|
								        for rec in self:
							 | 
						|
								            if len(rec.pos_cross_product_ids) < 0:
							 | 
						|
								                raise ValidationError(_("Please add the cross products lines"))
							 | 
						|
								
							 | 
						|
								    def get_cross_selling_products(self, product_id):
							 | 
						|
								        """
							 | 
						|
								        Getting the required values for the tables
							 | 
						|
								         and return the values to that template
							 | 
						|
								        """
							 | 
						|
								        cross = self.env['pos.cross.selling'].search(
							 | 
						|
								            [('product_id', '=', product_id)])
							 | 
						|
								        vals = []
							 | 
						|
								        for rec in cross.pos_cross_product_ids:
							 | 
						|
								            vals.append({
							 | 
						|
								                'id': rec.product_id.id,
							 | 
						|
								                'image': '/web/image?model=product.product&field=image_128&id='
							 | 
						|
								                         + str(rec.product_id.id),
							 | 
						|
								                'name': rec.product_id.name,
							 | 
						|
								                'symbol': rec.product_id.cost_currency_id.symbol,
							 | 
						|
								                'price': rec.product_id.lst_price,
							 | 
						|
								                'selected': False})
							 | 
						|
								        return vals
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class PosCrossSellingLine(models.Model):
							 | 
						|
								    """Pos Cross-Selling Products Line"""
							 | 
						|
								    _name = 'pos.cross.selling.line'
							 | 
						|
								    _description = 'POS Cross-Selling Product Line'
							 | 
						|
								
							 | 
						|
								    product_id = fields.Many2one('product.product',
							 | 
						|
								                                 domain=[('available_in_pos', '=', 'True')],
							 | 
						|
								                                 required=True, string='Product Name',
							 | 
						|
								                                 help="Product details")
							 | 
						|
								    active = fields.Boolean(string='Active',
							 | 
						|
								                            help="To check the cross selling is active or not",
							 | 
						|
								                            default=True)
							 | 
						|
								    pos_cross_product_id = fields.Many2one('pos.cross.selling',
							 | 
						|
								                                           string='Pos Cross products',
							 | 
						|
								                                           help="Pos Cross products")
							 | 
						|
								
							 |