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

[14.0][BUG] Restore product default code #140356

Open
ilyasProgrammer opened this issue Oct 30, 2023 · 1 comment
Open

[14.0][BUG] Restore product default code #140356

ilyasProgrammer opened this issue Oct 30, 2023 · 1 comment
Labels
Sales Sales

Comments

@ilyasProgrammer
Copy link

ilyasProgrammer commented Oct 30, 2023

Problem: When you delete attributes from product template default_code is not restored.

Versions: 14.0. Looks like it is in master as well.

Steps to reproduce:

  1. Create new Product Template.
  2. Set default_code. Save.
  3. Add attribute with minimum 2 values. Save. Default code is False now.
  4. Delete attribute lines from product template. Save. Default code still False.

Expected behavior: default_code must be restored from single related product variant.

Suggestions:

    @api.depends('product_variant_ids', 'product_variant_ids.default_code')
    def _compute_default_code(self):
        unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
        for template in unique_variants:
            template.default_code = template.product_variant_ids.default_code
        for template in (self - unique_variants):
            template.default_code = False

This method must be triggered after you unarchive first product variant, but it is not.

It can be fixed like this:

class ProductProduct(models.Model):
    _inherit = "product.product"

   def write(self, values):
        res = super().write(values)
        if values.get('active') and values['active']:
            # _compute_default_code is not triggered by default in this case
            self.product_tmpl_id._compute_default_code()
        return res
```
@vava-odoo vava-odoo added the Sales Sales label Nov 17, 2023
@vava-odoo
Copy link
Contributor

Hi @ilyasProgrammer
Thanks for your report. @Feyensv could you have look?
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sales Sales
Projects
None yet
Development

No branches or pull requests

2 participants