diff --git a/product_expiry_configurable/migrations/16.0.1.0.0/post-migrate.py b/product_expiry_configurable/migrations/16.0.1.0.0/post-migrate.py new file mode 100644 index 00000000000..922aa140afc --- /dev/null +++ b/product_expiry_configurable/migrations/16.0.1.0.0/post-migrate.py @@ -0,0 +1,46 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _fill_in_columns(env): + """ + Create columns to fill in the previous module 'specific' fields + """ + if openupgrade.column_exists( + env.cr, "product_category", "specific_expiration_time" + ): + query = """ + UPDATE product_category + SET expiration_time = specific_expiration_time + """ + openupgrade.logged_query(env.cr, query) + if openupgrade.column_exists(env.cr, "product_category", "specific_use_time"): + query = """ + UPDATE product_category + SET use_time = specific_use_time + """ + openupgrade.logged_query(env.cr, query) + if openupgrade.column_exists(env.cr, "product_category", "specific_use_time"): + query = """ + UPDATE product_category + SET use_time = specific_use_time + """ + openupgrade.logged_query(env.cr, query) + if openupgrade.column_exists(env.cr, "product_category", "specific_removal_time"): + query = """ + UPDATE product_category + SET removal_time = specific_removal_time + """ + openupgrade.logged_query(env.cr, query) + if openupgrade.column_exists(env.cr, "product_category", "specific_alert_time"): + query = """ + UPDATE product_category + SET alert_time = specific_alert_time + """ + openupgrade.logged_query(env.cr, query) + + +@openupgrade.migrate() +def migrate(env, version): + _fill_in_columns(env) diff --git a/product_expiry_configurable/migrations/16.0.1.0.0/pre-migrate.py b/product_expiry_configurable/migrations/16.0.1.0.0/pre-migrate.py new file mode 100644 index 00000000000..ccaa34c3fd4 --- /dev/null +++ b/product_expiry_configurable/migrations/16.0.1.0.0/pre-migrate.py @@ -0,0 +1,50 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _create_columns(env): + """ + Create columns to fill in the previous module 'specific' fields + """ + field_names = [ + ( + "expiration_time", + "product.category", + "product_category", + "integer", + "integer", + "product_expiry_configurable", + ), + ( + "use_time", + "product.category", + "product_category", + "integer", + "integer", + "product_expiry_configurable", + ), + ( + "removal_time", + "product.category", + "product_category", + "integer", + "integer", + "product_expiry_configurable", + ), + ( + "alert_time", + "product.category", + "product_category", + "integer", + "integer", + "product_expiry_configurable", + ), + ] + if not openupgrade.column_exists(env.cr, "product_category", "expiration_time"): + openupgrade.add_fields(env, field_names) + + +@openupgrade.migrate() +def migrate(env, version): + _create_columns(env) diff --git a/product_expiry_configurable/models/product_template.py b/product_expiry_configurable/models/product_template.py index 5bc2ec0edc8..bc2a808f766 100644 --- a/product_expiry_configurable/models/product_template.py +++ b/product_expiry_configurable/models/product_template.py @@ -11,7 +11,6 @@ class ProductTemplate(models.Model): use_expiration_date = fields.Boolean( compute="_compute_use_expiration_date", readonly=False, store=True ) - expiration_time = fields.Integer( compute="_compute_date_fields", store=True, diff --git a/product_expiry_configurable/models/stock_lot.py b/product_expiry_configurable/models/stock_lot.py index 8e8d0a0b673..a32838875d2 100644 --- a/product_expiry_configurable/models/stock_lot.py +++ b/product_expiry_configurable/models/stock_lot.py @@ -36,17 +36,21 @@ def _search_quants_domain(self, expiry_lots): ("location_id.scrap_location", "=", False), ] + def _get_expired_lots_domain_for_remind(self, date_field, date_reminded_field): + return [ + (date_field, "<=", fields.Date.today()), + (date_reminded_field, "=", False), + ] + @api.model def _expiry_date_exceeded(self, date_field=False): """Log an activity on internally stored lots whose "date" field has been reached. No further activity will be generated on lots whose "date" has already been reached (even if the "date" is changed). """ - date_reminded_field = "%s_reminded" % date_field - expiry_lots = self.env["stock.lot"].search( - [(date_field, "<=", fields.Date.today()), (date_reminded_field, "=", False)] + self._get_expired_lots_domain_for_remind(date_field, date_reminded_field) ) lot_stock_quants = self.env["stock.quant"].search(