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

pattern_import_export_xlsx: support date/datetime #113

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pattern_import_export_xlsx/models/pattern_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
from datetime import date, datetime
from io import BytesIO

import openpyxl

from odoo import _, models
from odoo import _, fields, models
from odoo.exceptions import UserError

STOP_AFTER_NBR_EMPTY = 10


def format_data(value):
if isinstance(value, datetime):
return fields.Datetime.to_string(value)
elif isinstance(value, date):
return fields.Date.to_string(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof may be better.

else:
return value


class PatternFile(models.Model):
_inherit = "pattern.file"

Expand Down Expand Up @@ -48,7 +58,7 @@ def _parse_data_xlsx(self, data):
if self.pattern_config_id.nr_of_header_rows == idx + 1:
headers = [x.value for x in row]
elif headers:
vals = [x.value for x in row]
vals = [format_data(x.value) for x in row]
if any(vals):
count_empty = 0
item = dict(zip(headers, vals))
Expand Down