diff --git a/connector_extension/models/binding/binding.py b/connector_extension/models/binding/binding.py index 53de6e30e..0ac681242 100644 --- a/connector_extension/models/binding/binding.py +++ b/connector_extension/models/binding/binding.py @@ -38,6 +38,27 @@ def import_data(self, backend_record, domain=None, delayed=True): @api.model def export_data(self, backend_record, domain=None, delayed=True): """Prepare the batch export records to Channel""" + # Cursor-rebind workaround for OCA/queue queue_job (16.0+). + # `Job.in_temporary_env()` (added by OCA/queue#910 / commit f2bfda90) + # only rebinds `self.recordset` to the new cursor opened when + # `allow_commit=True`; it does NOT rebind args. Without this manual + # rebind, `backend_record.work_on()` builds a `WorkContext` whose + # `env` is the OUTER cursor (with `_prevent_commit` patched on + # `cr.commit`), so `binder.bind_export()` at `binder.py:315` still + # raises RuntimeError("Commit is forbidden in queue jobs") despite + # `allow_commit=True` being set. Pattern (cursor-only swap, preserves + # uid/su/context captured at `_job_prepare_context_before_enqueue`) + # matches what queue_job uses internally for `self.recordset`, and + # what @guewen (queue_job maintainer) himself suggested in + # OCA/queue#889 ("such export_record and such are implementation + # specific and need to be fixed in many places"). The OCA wiki page + # https://github.com/OCA/queue/wiki/Upgrade-warning:-commits-inside-jobs + # does NOT document this args-rebinding limitation. + # Same fix applied below in export_batch, export_record, + # export_delete_record. Imports do not need it because bind_import + # does not commit. + # Refs: OCA/queue#889, OCA/queue#910, OCA/connector#522. + backend_record = backend_record.with_env(backend_record.env(cr=self.env.cr)) if delayed: model = self.with_delay() return model.export_batch( @@ -61,6 +82,8 @@ def import_batch(self, backend_record, domain=None, delayed=True, use_data=True) @api.model def export_batch(self, backend_record, domain=None, delayed=True): """Prepare the batch export of records modified on Odoo""" + # Cursor-rebind workaround for queue_job; see export_data for rationale. + backend_record = backend_record.with_env(backend_record.env(cr=self.env.cr)) if not domain: domain = [] with backend_record.work_on(self._name) as work: @@ -102,6 +125,9 @@ def import_record(self, backend_record, external_id, sync_date, external_data=No @api.model def export_record(self, backend_record, relation): """Export Odoo record""" + # Cursor-rebind workaround for queue_job; see export_data for rationale. + backend_record = backend_record.with_env(backend_record.env(cr=self.env.cr)) + relation = relation.with_env(relation.env(cr=self.env.cr)) with backend_record.work_on(self._name) as work: exporter = work.component(usage="record.direct.exporter") return exporter.run(relation) @@ -109,6 +135,9 @@ def export_record(self, backend_record, relation): @api.model def export_delete_record(self, backend_record, relation): """Export Odoo record""" + # Cursor-rebind workaround for queue_job; see export_data for rationale. + backend_record = backend_record.with_env(backend_record.env(cr=self.env.cr)) + relation = relation.with_env(relation.env(cr=self.env.cr)) with backend_record.work_on(self._name) as work: deleter = work.component(usage="record.direct.export.deleter") return deleter.run(relation) diff --git a/connector_sapb1/README.rst b/connector_sapb1/README.rst index d11a32361..655cfe4ac 100644 --- a/connector_sapb1/README.rst +++ b/connector_sapb1/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ================ Connector SAP B1 ================ @@ -13,7 +17,7 @@ Connector SAP B1 .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-nuobit%2Fodoo--addons-lightgray.png?logo=github diff --git a/connector_sapb1/__manifest__.py b/connector_sapb1/__manifest__.py index c641ccf28..e780bcbe5 100644 --- a/connector_sapb1/__manifest__.py +++ b/connector_sapb1/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Connector SAP B1", - "version": "16.0.1.0.0", + "version": "16.0.1.0.1", "author": "NuoBiT Solutions SL", "license": "AGPL-3", "category": "Connector", diff --git a/connector_sapb1/data/queue_job_function_data.xml b/connector_sapb1/data/queue_job_function_data.xml index c78e149d2..8802e8c3f 100644 --- a/connector_sapb1/data/queue_job_function_data.xml +++ b/connector_sapb1/data/queue_job_function_data.xml @@ -17,4 +17,60 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)--> + + + + export_record + + + + + + + export_record + + + + + + + export_record + + + + + + + export_record + + + + + + + export_record + + + + diff --git a/connector_sapb1/migrations/16.0.1.0.1/pre-migration.py b/connector_sapb1/migrations/16.0.1.0.1/pre-migration.py new file mode 100644 index 000000000..85defa303 --- /dev/null +++ b/connector_sapb1/migrations/16.0.1.0.1/pre-migration.py @@ -0,0 +1,59 @@ +"""Pre-migration: claim auto-created queue.job.function records. + +Existing installs may have queue.job.function records for export_record on +sapb1 binding models that were auto-created and have no ir_model_data entry +(thus no xml_id). When the new XML definition loads with noupdate="1", +Odoo would try to CREATE records with our new xml_ids, which fails due to +the (model_id, method) unique constraint. + +Solution: insert the ir_model_data entries BEFORE the XML loads, so each +xml_id is already linked to the existing record. Also set allow_commit=True +directly (since noupdate="1" prevents the XML from updating fields). + +See: https://github.com/OCA/queue/wiki/Upgrade-warning:-commits-inside-jobs +""" + +JOB_FUNCTIONS = [ + ("sapb1_binding_method_export_record_job_function", "sapb1.binding"), + ("sapb1_res_partner_export_record_job_function", "sapb1.res.partner"), + ("sapb1_sale_order_export_record_job_function", "sapb1.sale.order"), + ("sapb1_sale_order_line_export_record_job_function", "sapb1.sale.order.line"), + ("sapb1_product_product_export_record_job_function", "sapb1.product.product"), +] + + +def migrate(cr, version): + if not version: + return + for xml_id, model_name in JOB_FUNCTIONS: + cr.execute( + """ + SELECT qjf.id + FROM queue_job_function qjf + JOIN ir_model im ON im.id = qjf.model_id + WHERE qjf.method = 'export_record' AND im.model = %s + """, + (model_name,), + ) + row = cr.fetchone() + if not row: + continue + qjf_id = row[0] + cr.execute( + """ + INSERT INTO ir_model_data + (module, name, model, res_id, noupdate) + VALUES + ('connector_sapb1', %s, 'queue.job.function', %s, TRUE) + ON CONFLICT (module, name) DO NOTHING + """, + (xml_id, qjf_id), + ) + cr.execute( + """ + UPDATE queue_job_function + SET allow_commit = TRUE + WHERE id = %s + """, + (qjf_id,), + ) diff --git a/connector_sapb1/static/description/index.html b/connector_sapb1/static/description/index.html index 9c2813944..f441c98d5 100644 --- a/connector_sapb1/static/description/index.html +++ b/connector_sapb1/static/description/index.html @@ -1,18 +1,18 @@ - -Connector SAP B1 +README.rst -
-

Connector SAP B1

+
+ + +Odoo Community Association + +
+

Connector SAP B1

-

Beta License: AGPL-3 nuobit/odoo-addons

+

Beta License: AGPL-3 nuobit/odoo-addons

SAP Business One connector

Table of contents

@@ -384,7 +389,7 @@

Connector SAP B1

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -392,15 +397,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • NuoBiT Solutions SL
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is part of the nuobit/odoo-addons project on GitHub.

You are welcome to contribute.

+