server-ux/barcode_action/models/res_partner.py

36 lines
1.3 KiB
Python
Raw Normal View History

2021-03-23 19:15:27 +00:00
# Copyright 2018 Creu Blanca
# Copyright 2020 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import json
from flectra import _, models
from flectra.tools.safe_eval import safe_eval
class ResPartner(models.Model):
_inherit = "res.partner"
def find_res_partner_by_ref_using_barcode(self, barcode):
partner = self.search([("ref", "=", barcode)], limit=1)
if not partner:
2022-02-06 03:14:41 +00:00
xmlid = "barcode_action.res_partner_find"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
context = safe_eval(action["context"])
2021-03-23 19:15:27 +00:00
context.update(
{
"default_state": "warning",
"default_status": _(
"Partner with Internal Reference " "%s cannot be found"
)
% barcode,
}
)
2022-02-06 03:14:41 +00:00
action["context"] = json.dumps(context)
return action
xmlid = "base.action_partner_form"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
2021-03-23 19:15:27 +00:00
res = self.env.ref("base.view_partner_form", False)
2022-02-06 03:14:41 +00:00
action["views"] = [(res and res.id or False, "form")]
action["res_id"] = partner.id
return action