skilld-labs / go-odoo

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

How to create partner #20

Closed happilymarrieddad closed 5 years ago

happilymarrieddad commented 5 years ago

Hey guys,

I can create a partner with the API but I can't seem to create certain fields. Anytime there is a field with more than 1 word in it's name I can't ever get that field to be added. For example, if I want to create a partner then I can easily assign "name" to the map and that works but if I try ParentName then no matter what case I try it never works. Here are the cases I've tried

  1. ParentName
  2. parentname
  3. parentName
  4. parent_name

Is there an example of a create with one of these fields that has more than 1 word in it? Thanks!

Here is the script I've been using (I removed my credentials... didn't see a point in including those)

package main

import (
    "fmt"

    "github.com/davecgh/go-spew/spew"
    API "github.com/skilld-labs/go-odoo/api"
    TYPES "github.com/skilld-labs/go-odoo/types"
)

func main() {
    client, err := API.NewClient("some_url", nil)
    if err != nil {
        panic(err)
    }
    err = client.Login("some_database", "some_email", "some_email")
    if err != nil {
        panic(err)
    }

    fmt.Println("Connected!")

    service := API.NewResPartnerService(client)

    var relations TYPES.Relations

    n := make(map[string]interface{})

    n["name"] = "Nick Test"
    n["ref"] = 1654847
    n["parent_name"] = "ParentName"

    id, err := service.Create(n, &relations)
    if err != nil {
        panic(err)
    }

    // Products
    //service := api.NewProductProductService(client)

    // service := api.NewProductProductService(client)

    res, err := service.GetByIds([]int64{id})
    if err != nil {
        panic(err)
    }

    spew.Dump(res)

    err = service.Delete([]int64{id})
    if err != nil {
        panic(err)
    }
}

Also, what is the point in the relations object? It doesn't seem to do anything. Thanks!

happilymarrieddad commented 5 years ago

selection_073

ahuret commented 5 years ago

Hi @happilymarrieddad !

All fields name have been "reworked" since Golang good practices says to use CamelCase (here fields are public so first letter as uppercase). Odoo is python, so all is coded with snake_case, here ParentName is parent_name in Odoo. So, when we call api, we have to use odoo rule (snake_case). => The fourth choice was good :-)

For your case:

If you want to modify parent_name, you first got to link the partner with the parent of your choice (with parent_id field), then parent_name will appear with the parent_id.name value ! (I've checked btw and it works this way :) )

Also, what is the point in the relations object? It doesn't seem to do anything. Thanks!

Relations is the representation in golang for more complicated objects like Many2One,Many2Many,One2Many etc...

Closing it ! Have a good day !

Antoine

happilymarrieddad commented 5 years ago

@antony360 Hey thanks! I was able to get it to work by just exploring the db and using the column names. Not sure if that's helpful to anyone but I thought I would add that in case. Thanks again!