-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from itpp-labs/16.0-links-and-data
commit is created by 👷♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
- Loading branch information
Showing
17 changed files
with
338 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev> | ||
# License MIT (https://opensource.org/licenses/MIT). | ||
from odoo import fields, models | ||
|
||
|
||
class IrModelFields(models.Model): | ||
_inherit = "ir.model.fields" | ||
|
||
sync_project_id = fields.Many2one( | ||
"sync.project", | ||
string="Sync Project", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev> | ||
import base64 | ||
import csv | ||
import json | ||
from io import StringIO | ||
|
||
import yaml | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class SyncData(models.Model): | ||
_name = "sync.data" | ||
_description = "Sync Data File" | ||
|
||
name = fields.Char("Technical name") | ||
project_id = fields.Many2one("sync.project", ondelete="cascade") | ||
file_name = fields.Char("File Name") | ||
file_content = fields.Binary("File Content") | ||
|
||
def csv(self, *args, **kwargs): | ||
"""Parse CSV file from binary field.""" | ||
if self.file_content: | ||
file_content = base64.b64decode(self.file_content) | ||
file_content = file_content.decode("utf-8") | ||
file_like_object = StringIO(file_content) | ||
reader = csv.DictReader(file_like_object, *args, **kwargs) | ||
return [row for row in reader] | ||
return [] | ||
|
||
def json(self): | ||
"""Parse JSON file from binary field.""" | ||
if self.file_content: | ||
file_content = base64.b64decode(self.file_content) | ||
file_content = file_content.decode("utf-8") | ||
return json.loads(file_content) | ||
return {} | ||
|
||
def yaml(self): | ||
"""Parse YAML file from binary field.""" | ||
if self.file_content: | ||
file_content = base64.b64decode(self.file_content) | ||
file_content = file_content.decode("utf-8") | ||
return yaml.safe_load(file_content) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.