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.
		
		
		
		
		
			
		
			
				
					
					
						
							83 lines
						
					
					
						
							3.8 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							83 lines
						
					
					
						
							3.8 KiB
						
					
					
				
								# -*- coding: utf-8 -*-
							 | 
						|
								###############################################################################
							 | 
						|
								#
							 | 
						|
								#    Cybrosys Technologies Pvt. Ltd.
							 | 
						|
								#
							 | 
						|
								#    Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
							 | 
						|
								#    Author: Cybrosys Techno Solutions(<https://www.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
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class ProductProductInherit(models.Model):
							 | 
						|
								    """Inherit the 'product_product' model to include Multiple References in
							 | 
						|
								    the form view."""
							 | 
						|
								    _inherit = 'product.product'
							 | 
						|
								
							 | 
						|
								    multiple_references_ids = fields.One2many("multiple.reference.per.product",
							 | 
						|
								                                              "product_id",
							 | 
						|
								                                              string="Multiple References",
							 | 
						|
								                                              help="Choose Multiple Reference"
							 | 
						|
								                                                   " per Product and checks "
							 | 
						|
								                                                   "simultaneously")
							 | 
						|
								    multiple_references_code = fields.Char(string="Multiple References",
							 | 
						|
								                                           related="multiple_references_ids"
							 | 
						|
								                                                   ".multiple_references_name",
							 | 
						|
								                                           help="Enter Code for Multiple "
							 | 
						|
								                                                "Reference")
							 | 
						|
								    multiple_product_references_ids = fields.Many2many(
							 | 
						|
								        "multiple.reference.per.product",
							 | 
						|
								        string="Multiple References",
							 | 
						|
								        compute="_get_multiple_reference",
							 | 
						|
								        help="Choose Multiple Reference"
							 | 
						|
								             "per Product")
							 | 
						|
								    multiple_references_count = fields.Integer(string="Number of references",
							 | 
						|
								                                               compute="_get_multiple_reference_count",
							 | 
						|
								                                               help="Enter Number of Reference")
							 | 
						|
								
							 | 
						|
								    @api.depends('multiple_product_references_ids')
							 | 
						|
								    def _get_multiple_reference_count(self):
							 | 
						|
								        """Function to get the count of reference code"""
							 | 
						|
								        self.multiple_references_count = len(self.multiple_references_ids)
							 | 
						|
								
							 | 
						|
								    def _get_multiple_reference(self):
							 | 
						|
								        """Function for getting all Multiple References"""
							 | 
						|
								        self.multiple_product_references_ids = self.multiple_references_ids.filtered(
							 | 
						|
								            lambda
							 | 
						|
								                references: references.multiple_references_name != self.default_code).ids
							 | 
						|
								
							 | 
						|
								    def multiple_references_list(self):
							 | 
						|
								        """Function to open the Multiple References form and tree view
							 | 
						|
								        when clicking the 'Add More' button."""
							 | 
						|
								        return {
							 | 
						|
								            'name': "Multiple References",
							 | 
						|
								            'type': 'ir.actions.act_window',
							 | 
						|
								            'target': 'current',
							 | 
						|
								            'res_model': 'multiple.reference.per.product',
							 | 
						|
								            'views': [[False, "list"], [False, "form"]],
							 | 
						|
								            'context': {'default_product_id': self.id},
							 | 
						|
								            'domain': [('product_id', '=', self.id)],
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								    def write(self, values):
							 | 
						|
								        """Function for update the Product Reference"""
							 | 
						|
								        if values.get('default_code'):
							 | 
						|
								            if self.default_code:
							 | 
						|
								                self.env[
							 | 
						|
								                    'multiple.reference.per.product'].sudo().create_reference(
							 | 
						|
								                    self.default_code, self.id)
							 | 
						|
								        res = super(ProductProductInherit, self).write(values)
							 | 
						|
								        return res
							 | 
						|
								
							 |