Skip to content

Commit

Permalink
[MIG] punchout: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benwillig authored and ThomasBinsfeld committed Dec 23, 2024
1 parent 98b5c6c commit ca4c2f4
Show file tree
Hide file tree
Showing 22 changed files with 1,977 additions and 53 deletions.
159 changes: 159 additions & 0 deletions punchout/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
========
Punchout
========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a575761638f19894b0e09efcaa56bf2fe5fe3f97a4ab1109909e8a2def537c5c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/16.0/punchout
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-punchout
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module setup the base configuration to access a punchout platform,
in order to populate odoo. For example, creating purchase orders. This
alpha version has been implemented using the eShop Wurth.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

[ This file is optional but strongly suggested to allow end-users to
evaluate the module's usefulness in their context. ]

This module set up the base of the connection to a punchout system. Sub
module can be created for example to create a purchase order from a
shopping cart created in the punchout platform. To do this, you can make
your model inherit from "punchout.request" and add the import process by
inheriting "action_process" method.

Linked modules:

- punchout_environment : allows to configure a punchout backend through
server environment files
- punchout_queue_job : link the punchout request to queue jobs,
automatically call the process method when a response is received

Installation
============

[ This file must only be present if there are very specific installation
instructions, such as installing non-python dependencies. The audience
is systems administrators. ]

Configuration
=============

[ This file is optional, it should explain how to configure the module
before using it; it is aimed at advanced users. ]

To configure this module, you need to access the "PunchOut Backend" menu
and create a new record.

Usage
=====

[ This file must be present and contains the usage instructions for
end-users. As all other rst files included in the README, it MUST NOT
contain reStructuredText sections only body text (paragraphs, lists,
tables, etc). Should you need a more elaborate structure to explain the
addon, please create a Sphinx documentation (which may include this file
as a "quick start" section). ]

To use this module, you need to:

1. Configure a punchout backend
2. Click the "Access button". It will create a punchout request.
3. Use the punchout backend website and trigger a response to Odoo
4. Check that the response has been correctly linked to the previously
created punchout request

Known issues / Roadmap
======================

[ Enumerate known caveats and future potential improvements. It is
mostly intended for end-users, and can also help potential new
contributors discovering new features to implement. ]

-

Changelog
=========

13.0.1.0.0 (2023-09-26)
-----------------------

- [ADD] First version.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/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
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20punchout%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Thomas Binsfeld [email protected] (ACSONE SA/NV)
- Benjamin Willig [email protected] (ACSONE SA/NV)

Other credits
-------------

[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

- ACSONE SA/NV

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/punchout>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion punchout/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Punchout",
"version": "13.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Odoo Community Association (OCA), ACSONE SA/NV",
"website": "https://github.com/OCA/edi",
Expand Down
4 changes: 2 additions & 2 deletions punchout/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from base64 import b64decode

from odoo.http import Controller, local_redirect, request, route
from odoo.http import Controller, request, route

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,4 +40,4 @@ def receive_punchout_response(self, backend_id, *args, **kwargs):
)
else:
redirect_url = punchout_session._get_redirect_url()
return local_redirect(redirect_url)
return request.redirect_query(redirect_url)
62 changes: 48 additions & 14 deletions punchout/models/punchout_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,69 @@ class PunchoutBackend(models.Model):
("name_unique", "unique(name)", _("This PunchOut backend already exists."))
]

name = fields.Char(string="Name", required=True,)
url = fields.Char(string="URL", required=True,)
name = fields.Char(
required=True,
)
description = fields.Char(
required=True,
)
url = fields.Char(
string="URL",
required=True,
)
from_domain = fields.Char(
string="From domain", required=True, groups="base.group_system",
string="From domain",
required=True,
groups="base.group_system",
)
from_identity = fields.Char(
string="From identity", required=True, groups="base.group_system",
string="From identity",
required=True,
groups="base.group_system",
)
to_domain = fields.Char(
string="To domain",
required=True,
)
to_domain = fields.Char(string="To domain", required=True,)
to_identity = fields.Char(
string="To identity", required=True, groups="base.group_system",
string="To identity",
required=True,
groups="base.group_system",
)
shared_secret = fields.Char(
string="Shared secret", required=True, groups="base.group_system",
string="Shared secret",
required=True,
groups="base.group_system",
)
user_agent = fields.Char(
string="User agent",
required=True,
)
user_agent = fields.Char(string="User agent", required=True,)
deployment_mode = fields.Char(
string="Deployment mode", help="Test or production", required=True,
string="Deployment mode",
help="Test or production",
required=True,
)
browser_form_post_url = fields.Char(
string="Browser form post URL",
help="Exposed URL where the shopping cart must be sent back to.",
required=True,
)
dtd_version = fields.Char(default="1.2.008",)
dtd_version = fields.Char(
default="1.2.008",
)
dtd_file = fields.Binary(
string="DTD File for validation", groups="base.group_system",
string="DTD File for validation",
groups="base.group_system",
)
dtd_filename = fields.Char(
groups="base.group_system",
)
dtd_filename = fields.Char(groups="base.group_system",)
state = fields.Selection(selection="_selection_state", default="draft")
session_duration = fields.Integer(string="Maximum session duration", default=7200,)
session_duration = fields.Integer(
string="Maximum session duration",
default=7200,
)

@api.constrains("session_duration")
def _check_session_duration(self):
Expand Down Expand Up @@ -103,7 +135,9 @@ def redirect_to_backend(self):
self._check_access_backend()
return (
self.env["punchout.session"]
.with_context(punchout_backend_id=self.id,)
.with_context(
punchout_backend_id=self.id,
)
._redirect_to_punchout()
)

Expand Down
45 changes: 34 additions & 11 deletions punchout/models/punchout_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,60 @@ class PunchoutSession(models.Model):
_order = "create_date desc"
_description = "Punchout Session"

backend_id = fields.Many2one(comodel_name="punchout.backend", readonly=True,)
backend_id = fields.Many2one(
comodel_name="punchout.backend",
readonly=True,
)
user_id = fields.Many2one(
comodel_name="res.users", readonly=True, default=lambda self: self.env.uid,
comodel_name="res.users",
readonly=True,
default=lambda self: self.env.uid,
)
buyer_cookie_id = fields.Char(readonly=True, string="Cookie")
punchout_url = fields.Char(readonly=True, string="Start URL")
cxml_setup_request = fields.Text(readonly=True, string="Setup Request",)
cxml_setup_request = fields.Text(
readonly=True,
string="Setup Request",
)
cxml_setup_request_response = fields.Text(
readonly=True, string="Setup Request Response",
readonly=True,
string="Setup Request Response",
)
cxml_response = fields.Text(
readonly=True,
string="Response",
)
cxml_response_date = fields.Datetime(
readonly=True,
string="Response Date",
)
cxml_response = fields.Text(readonly=True, string="Response",)
cxml_response_date = fields.Datetime(readonly=True, string="Response Date",)
expiration_date = fields.Datetime(
compute="_compute_expiration_date",
store=True,
readonly=True,
compute_sudo=True,
)
error_message = fields.Text(readonly=True,)
error_message = fields.Text(
readonly=True,
)
state = fields.Selection(
selection="_selection_state", default="draft", tracking=True,
selection="_selection_state",
default="draft",
tracking=True,
readonly=True,
)
action_process_allowed = fields.Boolean(compute="_compute_action_process_allowed")

@api.depends("state",)
@api.depends(
"state",
)
def _compute_action_process_allowed(self):
for rec in self:
rec.action_process_allowed = rec.state in ("to_process", "error")

@api.depends(
"backend_id", "create_date",
"backend_id",
"create_date",
)
def _compute_expiration_date(self):
for rec in self:
Expand Down Expand Up @@ -116,7 +139,7 @@ def _render_cxml_operation(self, template_xml_id, template_values=None):
cxml = (
self.env["ir.ui.view"]
.sudo()
.render_template(template_xml_id, template_values)
._render_template(template_xml_id, values=template_values)
)
cxml_request_element = ET.fromstring(cxml)
ET.indent(cxml_request_element)
Expand Down
Loading

0 comments on commit ca4c2f4

Please sign in to comment.