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

Syncing from upstream OCA/connector-interfaces (16.0) #120

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Available addons
----------------
addon | version | maintainers | summary
--- | --- | --- | ---
[connector_importer](connector_importer/) | 16.0.1.1.0 | [![simahawk](https://github.com/simahawk.png?size=30px)](https://github.com/simahawk) | This module takes care of import sessions.
[connector_importer](connector_importer/) | 16.0.1.1.1 | [![simahawk](https://github.com/simahawk.png?size=30px)](https://github.com/simahawk) | This module takes care of import sessions.
[connector_importer_product](connector_importer_product/) | 16.0.1.0.0 | | Ease definition of product imports using `connector_importer`.

[//]: # (end addons)
Expand Down
2 changes: 1 addition & 1 deletion connector_importer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Connector Importer
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7680b9cbb3329f4f4588d69d8487b9c03cae24d89c215adb8246c96b06f950fd
!! source digest: sha256:f7b849e3f22195c7a91d6e07ba38d714b8d54fe2c58d9815d59d6281f823bc3c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion connector_importer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Connector Importer",
"summary": """This module takes care of import sessions.""",
"version": "16.0.1.1.0",
"version": "16.0.1.1.1",
"depends": ["connector", "queue_job"],
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
49 changes: 41 additions & 8 deletions connector_importer/models/recordset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
import json
import os
from collections import OrderedDict

from odoo import api, fields, models

from odoo.addons.base_sparse_field.models.fields import Serialized
from odoo.addons.component.utils import is_component_registry_ready
from odoo.addons.queue_job.job import DONE, STATES

Expand Down Expand Up @@ -64,8 +65,8 @@ class ImportRecordset(models.Model):
create_date = fields.Datetime()
record_ids = fields.One2many("import.record", "recordset_id", string="Records")
# store info about imports report
report_data = Serialized()
shared_data = Serialized()
report_data = fields.Binary(attachment=True)
shared_data = fields.Binary(attachment=True)
report_html = fields.Html("Report summary", compute="_compute_report_html")
full_report_url = fields.Char(compute="_compute_full_report_url")
jobs_global_state = fields.Selection(
Expand Down Expand Up @@ -141,9 +142,27 @@ def _set_serialized(self, fname, values, reset=False):
"""Update serialized data."""
_values = {}
if not reset:
_values = self[fname]
_values = getattr(self, fname) or {}
if _values:
_values = self._get_json_from_binary(_values)

_values.update(values)
self[fname] = _values
json_report_data = json.dumps(_values)
_values = base64.b64encode(bytes(json_report_data, "utf-8"))
setattr(self, fname, _values)
# We need to invalidate the cache because the context dict
# bin_size=False triggers the _compute_datas(self) method
# which has the @api.depends_context('bin_size') decorator.
# Flush all pending computations and updates to the database.
domain = [
("res_model", "=", self._name),
("res_field", "=", fname),
("res_id", "in", self.ids),
]
attachments = self.env["ir.attachment"].sudo().search(domain)
if attachments:
attachments.invalidate_recordset(("datas", "raw"))

# Without invalidating cache we will have a bug because of Serialized
# field in odoo. It uses json.loads on convert_to_cache, which leads
# to all of our int dict keys converted to strings. Except for the
Expand All @@ -160,9 +179,19 @@ def set_report(self, values, reset=False):
self.ensure_one()
self._set_serialized("report_data", values, reset=reset)

def _get_json_from_binary(self, binary_data):
json_raw_data = {}
if binary_data:
json_raw_data = base64.b64decode(binary_data).decode("utf-8")
json_raw_data = json.loads(json_raw_data)
return json_raw_data

def get_report(self):
self.ensure_one()
return self.report_data or {}
json_raw_data = self._get_json_from_binary(
self.with_context(bin_size=False).report_data
)
return json_raw_data

def set_shared(self, values, reset=False):
"""Update import report values."""
Expand All @@ -171,7 +200,10 @@ def set_shared(self, values, reset=False):

def get_shared(self):
self.ensure_one()
return self.shared_data or {}
json_raw_data = self._get_json_from_binary(
self.with_context(bin_size=False).shared_data
)
return json_raw_data

def _prepare_for_import_session(self, start=True):
"""Wipe all session related data."""
Expand All @@ -180,9 +212,10 @@ def _prepare_for_import_session(self, start=True):
report_data["_last_start"] = fields.Datetime.to_string(
fields.Datetime.now()
)
json_report_data = json.dumps(report_data)
values = {
"record_ids": [(5, 0, 0)],
"report_data": report_data,
"report_data": base64.b64encode(bytes(json_report_data, "utf-8")),
"shared_data": {},
}
self.write(values)
Expand Down
14 changes: 8 additions & 6 deletions connector_importer/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Connector Importer</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7680b9cbb3329f4f4588d69d8487b9c03cae24d89c215adb8246c96b06f950fd
!! source digest: sha256:f7b849e3f22195c7a91d6e07ba38d714b8d54fe2c58d9815d59d6281f823bc3c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-interfaces/tree/16.0/connector_importer"><img alt="OCA/connector-interfaces" src="https://img.shields.io/badge/github-OCA%2Fconnector--interfaces-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-interfaces-16-0/connector-interfaces-16-0-connector_importer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-interfaces&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to import / update records from files using the connector
Expand Down Expand Up @@ -434,7 +434,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Loading