Skip to content

Commit

Permalink
Merge pull request #40 from Gedeelde-Weelde/bug/GED-69-import-problems
Browse files Browse the repository at this point in the history
bug: GED-69: Fix date handling in product changes tracking.
  • Loading branch information
jurcello authored Jan 9, 2025
2 parents 15b46f8 + 6916b59 commit a527b5b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
11 changes: 10 additions & 1 deletion product_import_cwa/models/cwa_product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ftplib
import logging
import os
from datetime import date

from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError, ValidationError
Expand Down Expand Up @@ -284,9 +285,17 @@ def _get_value_changes(self, new_vals, supplier_info):
old_value = getattr(supplier_info, field, None)
new_value = new_vals[field]
if old_value != new_value:
changes[field] = {"old": old_value, "new": new_value}
changes[field] = {
"old": self._check_date_and_fix_if_date(old_value),
"new": self._check_date_and_fix_if_date(new_value),
}
return changes

def _check_date_and_fix_if_date(self, value):
if isinstance(value, date):
return value.strftime("%Y-%m-%d") # Convert date to 'YYYY-MM-DD'
return value

@api.model
def load_records(self, keys, data, model):
data_chunks = split_data(data, split_size=CHUNKSIZE)
Expand Down
2 changes: 1 addition & 1 deletion product_import_cwa/tests/data/products_test_modified.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<rauwemelk>0</rauwemelk>
<inkoopprijs>2.3</inkoopprijs>
<consumentenprijs>3.9</consumentenprijs>
<ingangsdatum>2016-02-11</ingangsdatum>
<ingangsdatum>2017-02-11</ingangsdatum>
</product>
<product>
<eancode />
Expand Down
6 changes: 5 additions & 1 deletion product_import_cwa/tests/test_product_import_cwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ def test_a_changed_record_has_a_json_field_for_changes(self):

changes = {
"consumentenprijs": {"new": 3.9, "old": 3.7},
"ingangsdatum": {
"new": "2017-02-11",
"old": "2016-02-11",
},
"ingredients": {
"new": "INGREDIENTENN: BOEKWEIT, EEKHOORNS",
"old": "INGREDIENTEN: BOEKWEIT",
Expand Down Expand Up @@ -533,7 +537,7 @@ def test_a_changed_record_has_a_computed_field_for_changed_fields(self):
[("affected_product_id", "=", imported_product.id)]
)

changed_fields = "inkoopprijs, consumentenprijs, ingredients"
changed_fields = "inkoopprijs, consumentenprijs, ingangsdatum, ingredients"

self.assertEqual(changed_fields, import_result.changed_fields)

Expand Down
4 changes: 3 additions & 1 deletion product_import_cwa/views/cwa_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@
<field name="state">code</field>
<field name="code">
for record in records.filtered(lambda p: p.state == "new"):
record.to_product()
action = record.to_product()
if action:
action
</field>
</record>

Expand Down

0 comments on commit a527b5b

Please sign in to comment.