Skip to content
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

RFC: product_template_multi_link improvement. #307

Closed
lmignon opened this issue Oct 17, 2019 · 0 comments
Closed

RFC: product_template_multi_link improvement. #307

lmignon opened this issue Oct 17, 2019 · 0 comments

Comments

@lmignon
Copy link

lmignon commented Oct 17, 2019

In the current implementation, when you add a link from product a to product b, the reverse link is not shown on product b (even if the information exists). Moreover it's not possible to define new types of link without extending the addon.

I propose to improve the implementation to fix these to issues. It could look like

class ProductLinkType(models.Model):
    _name='product.link.type"

    name = fields.Char()
    inverse_name = fields.Char()


class ProductLink(models.Model):
    _name='product.link"

   product_tmpl_id_left = fiedls.Many2one()
   product_tmpl_id_right = fiedls.Many2one()  
   product_link_type = fields.Many2one()
   link_type_name = fields.Char(related="product_link_type.name") # left to right
   link_type_inverse_name = fields.Char(related="product_link_type.invese_name") # right to left

    @api.multi
    @api.constrains("product_tmpl_id_left", "product_tmpl_id_right")
    def _check_products(self):
        """
        This method checks whether:
            - the two products are different
            - there is only link between the same two templates for the same type
        :raise: ValidationError if not ok
        """
       pass

class ProductTemplate(models.Model):
    _inherit = "product.template"

    product_link_ids = fields.One2many(comodel_name="product.link")
        compute="_compute_product_link_ids",
    )


    @api.multi
    def _compute_product_link_ids(self):
        link_model = self.env["product.link"]
        domain = [
            "|",
            ("product_tmpl_id_left", "in", self.ids),
            ("product_tmpl_id_right", "in", self.ids),
        ]
        links = link_model.search(domain)
        links_by_product_id = defaultdict(link_model.browse)
        for link in links:
            links_by_product_id[link.product_tmpl_id_left.id] |= link
            links_by_product_id[link.product_tmpl_id_right.id] |= link
        for record in self:
            record.product_link_ids = links_by_product_id[
                record.id
            ]

With this kind of implementation:

  • it become easy to export the links between products with the right semantic depending of the place of the product into the relation (left of right)
  • when product a is linked to b, b is linked to a
  • it's easy to display all the links for one product
  • you are not restricted to the predefined list of link types
  • ????
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 15, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 15, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 15, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 16, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 16, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 16, 2019
lmignon added a commit to acsone/e-commerce that referenced this issue Nov 21, 2019
HviorForgeFlow pushed a commit to ForgeFlow/e-commerce that referenced this issue May 15, 2020
lmignon added a commit to acsone/e-commerce that referenced this issue Jun 12, 2020
rousseldenis pushed a commit to acsone/e-commerce that referenced this issue Oct 15, 2020
rousseldenis pushed a commit to acsone/e-commerce that referenced this issue Oct 15, 2020
rousseldenis pushed a commit to acsone/e-commerce that referenced this issue Oct 23, 2020
acsonefho pushed a commit to acsone/e-commerce that referenced this issue Nov 2, 2021
HviorForgeFlow pushed a commit to ForgeFlow/e-commerce that referenced this issue Oct 6, 2022
HviorForgeFlow pushed a commit to ForgeFlow/e-commerce that referenced this issue Oct 6, 2022
HviorForgeFlow pushed a commit to ForgeFlow/e-commerce that referenced this issue Feb 6, 2023
HviorForgeFlow pushed a commit to ForgeFlow/e-commerce that referenced this issue Feb 6, 2023
sbejaoui pushed a commit to acsone/e-commerce that referenced this issue Mar 20, 2023
sbejaoui pushed a commit to acsone/e-commerce that referenced this issue Mar 20, 2023
Pablocce pushed a commit to factorlibre/e-commerce that referenced this issue Apr 22, 2024
Pablocce pushed a commit to factorlibre/e-commerce that referenced this issue Apr 22, 2024
David-Luis-Mora pushed a commit to David-Luis-Mora/e-commerce that referenced this issue May 2, 2024
David-Luis-Mora pushed a commit to David-Luis-Mora/e-commerce that referenced this issue May 2, 2024
thienvh332 pushed a commit to thienvh332/e-commerce that referenced this issue Nov 28, 2024
thienvh332 pushed a commit to thienvh332/e-commerce that referenced this issue Nov 28, 2024
adhoc-cicd-bot pushed a commit to adhoc-cicd/oca-e-commerce that referenced this issue Jan 13, 2025
adhoc-cicd-bot pushed a commit to adhoc-cicd/oca-e-commerce that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant