# -*- coding: utf-8 -*- ############################################################################### # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2024-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # 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 . # ############################################################################### 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