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

[14.0][IMP] edi_oca: Add new model edi.configuration #1035

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from

Conversation

thienvh332
Copy link
Contributor

@thienvh332 thienvh332 commented Sep 6, 2024

Specs

In edi_oca

Add generic edi.configuration model with these characteristics:

Fields

active
code
  uniq identifier, normalized
description: describe what the conf is for
backend_id
type_id

model: model the conf applies to

partner_ids: Apply the conf on specific partners (Leave blank to apply all partners)

trigger: Selection field to make easier and more explicit the use of the conf for a specific event (eg: on_post_account_move, on_so_confirm, etc)
    default option: empty

snippet_before_do: validate the state, used to collect records todo
    can be used to do anything before the action that triggered it
  
    eval ctx:
        trigger = create/write/$name_of_the_event
        conf = current conf

    the snippet can return:
        todo = True/False
        snippet_do_vars = {}  # set of variables to pass over to the next snippet
        event_only
        tracked_fields
        edi_action
        .. in fact, any other variable that might be needed

snippet_do: used to do something specific here

    receives: operation, edi_action, vals, old_vals

This model can then be used by conf consumers.
Other methods:

edi_exec_snippet_before_do(self, record):
  exec before snippet, self=conf

edi_exec_snippet_do(self, record):
  exec snippet, self=conf

edi_get_conf(self, trigger, model_name=None, partners=None, backend=None):
  filter current recordset based on conditions

Backend / Exc. record

In `edi.backend._check_output_exchange_sync` move the loop on new_records to a new method `exchange_generate_send` whereas if the file has to be generated
2 jobs are chained (generate + send) if only send is needed, delay only one job.

Then add edi.exchange.record.action_exchange_generate_send and use that method from backend.
Consumer mixin

Specific fields for configuration (eg: edi_purchase_conf_ids) will be added by glue modules on res.partner.

Default conf

add generic conf for send_via_email

code: send_via_email
trigger: on_email_send
snippet: `record._edi_send_via_email()

add generic conf for send_via_edi

code: send_via_edi
trigger: none
snippet: `record._edi_send_via_edi(conf.type_id)

NOTE: sending emails is not really bound to edi
but in real life it's handy to have a default way to send EDI docs via email.
You could even generate an exchange record to keep track of that
but the choice will be up to the implementers.
The key is that w/ this features they can do whatever they want.

Views

add a specific menu item in edi settings to see all confs
make them searchable by model, active/inactive, partner, exc type, trigger

On edi_purchase_oca

add conf trigger on_button_confirm_purchase_order

add res.partner.edi_purchase_conf_ids
domain model=purchase.order, default_model=purchase.order, default_res_id=active_id

(document this approach in edi_oca readme section for edi.conf)

add generic conf for send_via_email_rfq

code: send_via_email_rfq
snippet: `record._edi_send_via_email(ir_action=record.action_rfq_send())

Example of specific listener implementation:

class EDIConfigPurchaseListener(Component):
    _name = "edi.config.consumer.listener.purchase.order"
    _inherit = "base.event.listener"

def on_button_confirm_purchase_order(self, record):
    trigger = "on_button_confirm_purchase_order"
    confs = record.edi_purchase_conf_ids.edi_get_conf(trigger)
    for conf in confs:
        conf.edi_exec_snippet_do(record)

@OCA-git-bot
Copy link
Contributor

Hi @etobella, @simahawk,
some modules you are maintaining are being modified, check this out!

@etobella
Copy link
Member

etobella commented Sep 6, 2024

More information would be awesome in order to understand why you did this.

@simahawk
Copy link
Contributor

simahawk commented Sep 6, 2024

@etobella this origins from our discussion on OCA/edi-framework#39
@thienvh332 I'm adding the specs I gave you in the description feel free to adapt / add more things.
IMO we should split the purchase part when ready (let's say before switching from draft to real PR to ease the final review of both parts).

@simahawk
Copy link
Contributor

simahawk commented Sep 6, 2024

@thienvh332 as it's draft, do you want us to wait for a review?

@nilshamerlinck
Copy link
Contributor

hi @simahawk

  • yes, please wait before reviewing, we need to finalize the internal review on our side
  • now that you confirmed you want this in v14, we'll complete it asap

@thienvh332 thienvh332 force-pushed the 14.0-imp-edi_oca branch 6 times, most recently from 0a7f624 to 92b7973 Compare September 18, 2024 08:56
@thienvh332 thienvh332 marked this pull request as ready for review September 18, 2024 11:11
@thienvh332
Copy link
Contributor Author

Hello @simahawk ,
This PR is ready for review. Could you please take a look at it?

@simahawk
Copy link
Contributor

simahawk commented Oct 9, 2024

can you drop the pypdf fix? 15a994e

):
# Default action if not provided
if ir_action is None:
# `action_send_email` is just an action name I created
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get what's the need for this ... there's no action_send_email anywhere.

code = fields.Char(required=True, copy=False, index=True, unique=True)
description = fields.Char(help="Describe what the conf is for")
backend_id = fields.Many2one(string="Backend", comodel_name="edi.backend")
type_id = fields.Many2one(
Copy link
Contributor

Choose a reason for hiding this comment

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

type should be mandatory

help="Model the conf applies to. Leave blank to apply for all models",
)
model_name = fields.Char(related="model.model", store=True)
partner_ids = fields.Many2many(
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need for a partner_ids field. The conf should be stored on the partner on a specific field per app or module (eg: edi_purchase_conf_ids).
The goal is to have clarity on UI on what confs are used for.
In fact, it's not in the specs.

def default_get(self, fields):
vals = super().default_get(fields)
model = self.env.context.get("default_model_name", False)
partners = self.env.context.get("default_partner_ids", False)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd choose which model field you want to be the master. If the model name is only used for searches, we don't need this.
Partners as well, can be trashed here.

@@ -0,0 +1,222 @@
# Copyright 2024 Camptocamp SA
Copy link
Contributor

Choose a reason for hiding this comment

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

This comes from the auto-type stuff, can you keep the authorship here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The license must be LGPL

from odoo.addons.component.core import Component


class EDIBackendListenerComponentConfig(Component):
Copy link
Contributor

Choose a reason for hiding this comment

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

this listener is useless IMO. See below.

_logger = logging.getLogger(__name__)


class EDIConfigurationMixin(models.AbstractModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we need this mixin. Is not in the specs... :/
Looks like a not required copy/past from *_auto module.

I think there's a big misunderstanding on WHO is supposed to trigger the specific action.
I wanted to simplify what I've done on *_auto module getting rid of all this automation and leave the control to the specific module and to the configuration that you can define.

Concept:

  1. the trigger is given by the specific module -> on_button_confirm_purchase_order must be an event triggered by the module edi_purchase_oca when button_confirm is called (which is already the case!)
  2. the condition to skip or exec a conf is defined on the conf itself -> that's why I described 2 methods (before_do and do)

@@ -7,10 +7,11 @@

class EdiExchangeConsumerTest(models.Model):
_name = "edi.exchange.consumer.test"
_inherit = ["edi.exchange.consumer.mixin"]
_inherit = ["edi.exchange.consumer.mixin", "edi.configuration.mixin"]
Copy link
Contributor

Choose a reason for hiding this comment

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

you can rollback this

_description = "Model used only for test"

name = fields.Char()
partner_id = fields.Many2one("res.partner")
Copy link
Contributor

Choose a reason for hiding this comment

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

why a partner_id? If there's no partner on the model we should not run anything or even break the init of the model if you are assigning configurations to a model w/o partners

def on_button_confirm_purchase_order(self, record):
trigger = "on_button_confirm_purchase_order"
for rec in record:
confs = self.env["edi.configuration"].edi_get_conf(
Copy link
Contributor

Choose a reason for hiding this comment

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

you are not using edi_purchase_conf_ids

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants