İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1982 Görünümler

I need customer module and customer info(here api response text)
example ı have one customer jack joe and a get info button 
click button and info comes json format to text field

Avatar
Vazgeç
Üretici En İyi Yanıt

hebele

Avatar
Vazgeç

if you are receiving any exception please share those details, when you say its not working, its hard to know what is not working.

Üretici

there is no error code ı cant figure it

En İyi Yanıt

yo can follow this steps:

  1. Create a new module: Create a new Odoo module with the necessary files and directories.

  2. Define the customer model: In your custom module, create a new Python file, let's call it customer.py, and define the customer model with the required fields. For example:

from odoo import fields, models

class Customer(models.Model):
_name = 'custom.module.customer'
_description = 'Customer'

​ name =fieldsChar(string='Name')

  1. Define the view: In the same module, create a new XML file, let's call it customer_view.xml, and define the view for the customer model. Include a button and a text field to display the API response. For example:


odoo>
data>
record model="ir.ui.view" id="view_customer_form">
field name="name">custom.module.customer.form
field name="model">custom.module.customer
field name="arch" type="xml">
form>
sheet>
group>
field name="name"/>
button name="get_customer_info" string="Get Info" type="object" class="oe_highlight"/>
field name="api_response_text" widget="text" readonly="1"/>
/group>
/sheet>
/form>
/field>
/record>
 /data>
/odoo>

  1. Implement the button action: In the customer.py file, add a method that will be called when the button is clicked. This method can make the API request and set the API response text in the api_response_text field. For example:

from odoo import models, fields, api

class Customer(models.Model):
_name = 'custom.module.customer'
_description = 'Customer'

name = fields.Char(string='Name')
api_response_text = fields.Text(string='API Response', readonly=True)

@api.multi
def get_customer_info(self):
# Make the API request and obtain the response
api_response = "API response text goes here"

# Set the API response text in the field
self.api_response_text = api_response

Make sure to replace the placeholder API response with the actual code to fetch the customer information from the API.

  1. Update the module manifest: In the __manifest__.py file of your custom module, include the necessary information, such as the module name, dependencies, and views.

After implementing these steps, you should be able to install the module and see the customer form view with the "Get Info" button. Clicking the button will trigger the get_customer_info() method, and the API response text will be displayed in the api_response_text field.



Avatar
Vazgeç