[IMP]pms_api_rest: Improvemente Api rest logs and PUT

This commit is contained in:
Darío Lodeiros
2024-03-16 11:14:53 +01:00
parent 052c0666fd
commit 053009c86b
5 changed files with 231 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
from odoo import fields, models
from odoo import _, api, fields, models
class PmsApiLog(models.Model):
@@ -72,3 +72,63 @@ class PmsApiLog(models.Model):
string="Response URL",
help="Response URL",
)
model_id = fields.Many2one(
string="Model",
help="Model",
comodel_name="ir.model",
)
def related_action_open_record(self):
"""Open a form view with the record(s) of the record log.
For instance, for a job on a ``pms.folio``, it will open a
``pms.product`` form view with the product record(s) concerned by
the job. If the job concerns more than one record, it opens them in a
list.
This is the default related action.
"""
self.ensure_one()
if "pms_api_log_id" in self.env[self.model_id.model]._fields:
records = self.env[self.model_id.model].search(
[("pms_api_log_id", "=", self.id)]
)
if not records:
return None
action = {
"name": _("Related Record"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": records._name,
}
if len(records) == 1:
action["res_id"] = records.id
else:
action.update(
{
"name": _("Related Records"),
"view_mode": "tree,form",
"domain": [("id", "in", records.ids)],
}
)
return action
@api.model
def create(self, vals):
"""
set pms_api_log_id and origin_json in related records
if record_ids id present in context
"""
log_record = super().create(vals)
if self.env.context.get("record_ids"):
records = self.env[self.env.context.get("model")].browse(
self.env.context.get("record_ids")
)
records.write(
{
"pms_api_log_id": log_record.id,
"origin_json": log_record.request,
}
)
return log_record