skilld-labs / go-odoo

Golang wrapper for Odoo API
Apache License 2.0
86 stars 62 forks source link

Unable to retrieve data from certain field #16

Closed allealdine closed 6 years ago

allealdine commented 6 years ago

I can retrieve data from res.partner object with the following script:

// Package customers displays the customers page.
package customers

import (
    "fmt"

    "net/http"
    "adsoft/lib/flight"
    "adsoft/core/router"
    "github.com/skilld-labs/go-odoo/api"
)

func Load() {
    router.Get("/customers", Index)
}

func Index(w http.ResponseWriter, r *http.Request) {
    c := flight.Context(w, r)

    d, err := api.NewClient("http://localhost:8405", nil)
    if err != nil {
        fmt.Println(err.Error())
    }
    err = d.Login("dbname", "admin", "password")
    if err != nil {
        fmt.Println(err.Error())
    }
    //get the sale order service
    s := api.NewResPartnerService(d)
    //call the function GetAll() linked to the sale order service
    partners, err := s.GetAll()
    if err != nil {
        fmt.Println(err.Error())
    }
    fmt.Println(partners)

    v := c.View.New("customers/index")
    v.Vars["partners"] = partners
    v.Render(w, r)

}
{{define "title"}}Our Customers{{end}}
{{define "head"}}{{end}}
{{define "content"}}
    <div class="page-header">
        <h1>{{template "title" .}}</h1>
    </div>

    {{range $n := .partners}}
        <div class="panel panel-default">
            <div class="panel-body">
                <p>Data:{{.}}</p>
            </div>
        </div>
    {{end}}

{{end}}
{{define "foot"}}{{end}}

But how could I get data from specific field?

because when i type:

...
    {{range $n := .partners}}
        <div class="panel panel-default">
            <div class="panel-body">
                <p>Data:{{.name}}</p>
            </div>
        </div>
    {{end}}
...

the following message appear:

Data:Template File Error: template: index.tmpl:11:14: executing "content" at <.name>: can't evaluate field name in type types.ResPartner
ahuret commented 6 years ago

Probably you should use an uppercase on name (<p>Data:{{.Name}}</p>)

allealdine commented 6 years ago

Perfect, it works now, thank you so much.