Skip to Content
मेन्यू
This question has been flagged
2 Replies
2512 Views

Hi, 


I'm building a custom addon for Odoo and I'm wondering if it would be possible to get, within the controller, the informations of the current model. 


For example, would it be possible to get the ID of the res.parner object I'm on ? I know how to get that information in the model but I can't figure it out how to get that in the controller. 


Here is my code 


@http.route('/myaddon/api-call', auth='user', csrf=False )
  def calling(self, **kwargs):
    theId = # How to get the ID of the res partner object I'm on ??
    payload = {   "Ctxt": "xxxxxxxxxxxxx",
                    "ID": theId,
                    }
    req = urllib.request.Request(url='https://myapi', headers={
        "Content-Type":"application/json"}, data = json.dumps(payload).encode())
    reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
    if reply.get("error"):
     print('Alert!!')
     raise Exception(reply["error"])
    return json.dumps(reply) 


All the code works great except how to get that Id. 


Do you know how to do it ?


Thanks !

Avatar
Discard
Best Answer

Hi,

Try this:@http.route('/myaddon/api-call', auth='user', csrf=False)

    def calling(self, **kwargs):

        partner_id = int(kwargs.get('partner_id', 0))  # assuming 'partner_id' is passed in the URL

        if not partner_id:

            raise ValueError('Partner ID not provided.')


        payload = {

            "Ctxt": "xxxxxxxxxxxxx",

            "ID": partner_id,

        }

        req = urllib.request.Request(

            url='https://myapi',

            headers={"Content-Type": "application/json"},

            data=json.dumps(payload).encode()

        )

        reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))

        if reply.get("error"):

            print('Alert!!')

            raise Exception(reply["error"])

        return json.dumps(reply)


Hope it helps

Avatar
Discard

def _get_basic_product_information_purchase(self, product_or_template, pricelist, combination, **kwargs):
basic_information = dict(
**product_or_template.read(['description_purchase', 'display_name'])[0]
)

if not product_or_template.is_product_variant:
basic_information['id'] = False
combination_name = combination._get_combination_name()
if combination_name:
basic_information.update(
display_name=f"{basic_information['display_name']} ({combination_name})"
)

price = product_or_template.standard_price

purchase_order_id = int(kwargs.get('purchase_order_id', 0))

if purchase_order_id:
# Fetch the purchase order
purchase_order = request.env['purchase.order'].browse(purchase_order_id)

if purchase_order and purchase_order.partner_id:
# Find the seller for the specific partner in the current purchase order
seller = product_or_template.seller_ids.filtered(lambda s: s.partner_id.id == purchase_order.partner_id.id)
if seller:
price = seller[0].price

return dict(
**basic_information,
price=price
)

hi there, i also try the same code that you provide but i didnt get the current id of purchase order. could you help me?

Author Best Answer

It does thanks!

Avatar
Discard
Related Posts Replies Views Activity
4
अक्तू॰ 21
37473
3
नव॰ 24
29794
2
फ़र॰ 23
3004
1
अग॰ 22
7757
1
दिस॰ 21
2687