-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
8.0 greenify product attribute #80
Conversation
@LeartS @clonedagain @pedrobaeza @lmignon @gurneyalex This greenifys product attribute and resolves the issue with duplicate key constraints. If we can get it merged then we can work out what we want to do surrounding the PR's below, hopefully by just moving, reusing the code that makes this green. The install is a nightmare, the demo data doesn't update until after the module is installed, and the write method is called when setting defaults at module install but because the sequence is not loaded, so even if it was called, it just returns '/' anyway as it isn't found. Calling write in auto_init still causes a duplicate violation so I had to use cr.execute and set a manual sequence. However the additional demo data is updated afterwards. I know I could have used startswith() but it is slow and products are written to a lot, so I chose slice syntax deliberately for the code check. While this is primarily a work around to greenify this branch, it is also useful in production. |
👍 |
@@ -39,6 +40,22 @@ class ProductProduct(models.Model): | |||
'The reference must be unique'), | |||
] | |||
|
|||
def _auto_init(self, cr, context=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use an install hooks odoo/odoo@4105b5f
Thanks for solving the problem 👍 |
:param cr: | ||
:return: void | ||
""" | ||
duplicate_ids = self.search(cr, SUPERUSER_ID, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can fix all the duplicates in 1 SQL query.
WITH product_duplicate_code AS (
SELECT id
,CASE WHEN (count(*) OVER (PARTITION BY default_code)) > 1 THEN
'mig-'
|| row_number() OVER (PARTITION BY default_code ORDER BY id)
|| '-'
|| COALESCE(default_code, '')
ELSE default_code END AS new_default_code,
row_number() OVER (PARTITION BY default_code ORDER BY id) as cpt
FROM product_product)
UPDATE
product_product AS pp
SET
default_code = new_default_code
FROM
product_duplicate_code AS pdc
WHERE
pp.id = pdc.id
AND pdc.cpt > 1
@gdgellatly Thank you for the fix! IMO it can be improved by using a pre-init-hook in place of overriding the auto_init method.
You can also find and fix duplicates entries in 1 query. (tested on a db with 10k products and run in 52 ms) |
@lmignon I have update to use a pre_init_hook as suggested, however given the purpose of this merge the RTE is over the top IMO and changes module behaviour too much and raises the skill level too much for maintainability, not everyone is familiar with RTE's so have just reduced to a single simple query. The main purpose is to greenify for demo data, and I'd rather the install failed than started overwriting already set codes. |
@gdgellatly Thank you for the change. I understand you POV. The main objective of my SQL request is to fix all duplicated entries when the module is installed on an existing instance so the SQL constrain can be applied. IMO it's very important to take care of this kind of situation since the installation will not fail if the constrain is not applied and you'll need to check your log file to detect this kind of Warning. |
@lmignon I understand but it is not the point of this pull request which is The Rte destroys data, you feel that is right as successful installation But regardless, neither is the point here. The failed builds are stopping On Fri, 19 Jun 2015 7:32 PM Laurent Mignon (ACSONE) <
|
Add pre_init_hook to manually set nulls and '/' default codes to a unique code to greenify branch add pragma to pre_init method as it must have completed successfully if module installs
b258615
to
3f18274
Compare
just rebased and cleaned up |
👍 |
8.0 greenify product attribute
8.0 greenify product attribute
Updates auto_init to set a default code in case one does not exist. Otherwise it causes failures in setting the unique index.
Addresses #77 and replaces #78