Skip to content

Commit

Permalink
add Many2One helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuret committed Apr 23, 2020
1 parent 5a523ce commit 30f0f81
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (c *Client) FindCrmLead(criteria *Criteria) (*CrmLead, error) {}
func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, error) {}
```

### Conversion
Generated models can be converted to `Many2One` easily.
```go
func (cl *CrmLead) Many2One() *Many2One {}
```

## Types

The library contains custom types to improve the usability :
Expand Down
5 changes: 5 additions & 0 deletions account_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type AccountAccounts []AccountAccount
// AccountAccountModel is the odoo model name
const AccountAccountModel = "account.account"

// Many2One convert AccountAccount to *Many2One.
func (aa *AccountAccount) Many2One() *Many2One {
return NewMany2One(aa.Id.Get(), "")
}

// CreateAccountAccount creates a new account.account model and returns its id.
func (c *Client) CreateAccountAccount(aa *AccountAccount) (int64, error) {
return c.Create(AccountAccountModel, aa)
Expand Down
5 changes: 5 additions & 0 deletions account_analytic_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type AccountAnalyticAccounts []AccountAnalyticAccount
// AccountAnalyticAccountModel is the odoo model name
const AccountAnalyticAccountModel = "account.analytic.account"

// Many2One convert AccountAnalyticAccount to *Many2One.
func (aaa *AccountAnalyticAccount) Many2One() *Many2One {
return NewMany2One(aaa.Id.Get(), "")
}

// CreateAccountAnalyticAccount creates a new account.analytic.account model and returns its id.
func (c *Client) CreateAccountAnalyticAccount(aaa *AccountAnalyticAccount) (int64, error) {
return c.Create(AccountAnalyticAccountModel, aaa)
Expand Down
5 changes: 5 additions & 0 deletions account_analytic_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type AccountAnalyticLines []AccountAnalyticLine
// AccountAnalyticLineModel is the odoo model name
const AccountAnalyticLineModel = "account.analytic.line"

// Many2One convert AccountAnalyticLine to *Many2One.
func (aal *AccountAnalyticLine) Many2One() *Many2One {
return NewMany2One(aal.Id.Get(), "")
}

// CreateAccountAnalyticLine creates a new account.analytic.line model and returns its id.
func (c *Client) CreateAccountAnalyticLine(aal *AccountAnalyticLine) (int64, error) {
return c.Create(AccountAnalyticLineModel, aal)
Expand Down
5 changes: 5 additions & 0 deletions account_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ type AccountInvoices []AccountInvoice
// AccountInvoiceModel is the odoo model name
const AccountInvoiceModel = "account.invoice"

// Many2One convert AccountInvoice to *Many2One.
func (ai *AccountInvoice) Many2One() *Many2One {
return NewMany2One(ai.Id.Get(), "")
}

// CreateAccountInvoice creates a new account.invoice model and returns its id.
func (c *Client) CreateAccountInvoice(ai *AccountInvoice) (int64, error) {
return c.Create(AccountInvoiceModel, ai)
Expand Down
5 changes: 5 additions & 0 deletions account_invoice_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type AccountInvoiceLines []AccountInvoiceLine
// AccountInvoiceLineModel is the odoo model name
const AccountInvoiceLineModel = "account.invoice.line"

// Many2One convert AccountInvoiceLine to *Many2One.
func (ail *AccountInvoiceLine) Many2One() *Many2One {
return NewMany2One(ail.Id.Get(), "")
}

// CreateAccountInvoiceLine creates a new account.invoice.line model and returns its id.
func (c *Client) CreateAccountInvoiceLine(ail *AccountInvoiceLine) (int64, error) {
return c.Create(AccountInvoiceLineModel, ail)
Expand Down
5 changes: 5 additions & 0 deletions account_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type AccountJournals []AccountJournal
// AccountJournalModel is the odoo model name
const AccountJournalModel = "account.journal"

// Many2One convert AccountJournal to *Many2One.
func (aj *AccountJournal) Many2One() *Many2One {
return NewMany2One(aj.Id.Get(), "")
}

// CreateAccountJournal creates a new account.journal model and returns its id.
func (c *Client) CreateAccountJournal(aj *AccountJournal) (int64, error) {
return c.Create(AccountJournalModel, aj)
Expand Down
5 changes: 5 additions & 0 deletions generator/cmd/tmpl/model.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type {{.StructName}}s []{{.StructName}}
// {{.StructName}}Model is the odoo model name
const {{.StructName}}Model = "{{ .Name }}"

// Many2One convert {{.StructName}} to *Many2One.
func ({{.VarName}} *{{.StructName}}) Many2One() *Many2One {
return NewMany2One({{.VarName}}.Id.Get(), "")
}

// Create{{.StructName}} creates a new {{ .Name }} model and returns its id.
func (c *Client) Create{{.StructName}}({{.VarName}} *{{.StructName}}) (int64, error) {
return c.Create({{.StructName}}Model, {{.VarName}})
Expand Down
5 changes: 5 additions & 0 deletions product_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ type ProductProducts []ProductProduct
// ProductProductModel is the odoo model name
const ProductProductModel = "product.product"

// Many2One convert ProductProduct to *Many2One.
func (pp *ProductProduct) Many2One() *Many2One {
return NewMany2One(pp.Id.Get(), "")
}

// CreateProductProduct creates a new product.product model and returns its id.
func (c *Client) CreateProductProduct(pp *ProductProduct) (int64, error) {
return c.Create(ProductProductModel, pp)
Expand Down
5 changes: 5 additions & 0 deletions product_supplierinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type ProductSupplierinfos []ProductSupplierinfo
// ProductSupplierinfoModel is the odoo model name
const ProductSupplierinfoModel = "product.supplierinfo"

// Many2One convert ProductSupplierinfo to *Many2One.
func (ps *ProductSupplierinfo) Many2One() *Many2One {
return NewMany2One(ps.Id.Get(), "")
}

// CreateProductSupplierinfo creates a new product.supplierinfo model and returns its id.
func (c *Client) CreateProductSupplierinfo(ps *ProductSupplierinfo) (int64, error) {
return c.Create(ProductSupplierinfoModel, ps)
Expand Down
5 changes: 5 additions & 0 deletions project_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ type ProjectProjects []ProjectProject
// ProjectProjectModel is the odoo model name
const ProjectProjectModel = "project.project"

// Many2One convert ProjectProject to *Many2One.
func (pp *ProjectProject) Many2One() *Many2One {
return NewMany2One(pp.Id.Get(), "")
}

// CreateProjectProject creates a new project.project model and returns its id.
func (c *Client) CreateProjectProject(pp *ProjectProject) (int64, error) {
return c.Create(ProjectProjectModel, pp)
Expand Down
5 changes: 5 additions & 0 deletions project_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type ProjectTasks []ProjectTask
// ProjectTaskModel is the odoo model name
const ProjectTaskModel = "project.task"

// Many2One convert ProjectTask to *Many2One.
func (pt *ProjectTask) Many2One() *Many2One {
return NewMany2One(pt.Id.Get(), "")
}

// CreateProjectTask creates a new project.task model and returns its id.
func (c *Client) CreateProjectTask(pt *ProjectTask) (int64, error) {
return c.Create(ProjectTaskModel, pt)
Expand Down
5 changes: 5 additions & 0 deletions res_company.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ type ResCompanys []ResCompany
// ResCompanyModel is the odoo model name
const ResCompanyModel = "res.company"

// Many2One convert ResCompany to *Many2One.
func (rc *ResCompany) Many2One() *Many2One {
return NewMany2One(rc.Id.Get(), "")
}

// CreateResCompany creates a new res.company model and returns its id.
func (c *Client) CreateResCompany(rc *ResCompany) (int64, error) {
return c.Create(ResCompanyModel, rc)
Expand Down
5 changes: 5 additions & 0 deletions res_partner.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ type ResPartners []ResPartner
// ResPartnerModel is the odoo model name
const ResPartnerModel = "res.partner"

// Many2One convert ResPartner to *Many2One.
func (rp *ResPartner) Many2One() *Many2One {
return NewMany2One(rp.Id.Get(), "")
}

// CreateResPartner creates a new res.partner model and returns its id.
func (c *Client) CreateResPartner(rp *ResPartner) (int64, error) {
return c.Create(ResPartnerModel, rp)
Expand Down
5 changes: 5 additions & 0 deletions res_partner_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type ResPartnerCategorys []ResPartnerCategory
// ResPartnerCategoryModel is the odoo model name
const ResPartnerCategoryModel = "res.partner.category"

// Many2One convert ResPartnerCategory to *Many2One.
func (rpc *ResPartnerCategory) Many2One() *Many2One {
return NewMany2One(rpc.Id.Get(), "")
}

// CreateResPartnerCategory creates a new res.partner.category model and returns its id.
func (c *Client) CreateResPartnerCategory(rpc *ResPartnerCategory) (int64, error) {
return c.Create(ResPartnerCategoryModel, rpc)
Expand Down
5 changes: 5 additions & 0 deletions res_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ type ResUserss []ResUsers
// ResUsersModel is the odoo model name
const ResUsersModel = "res.users"

// Many2One convert ResUsers to *Many2One.
func (ru *ResUsers) Many2One() *Many2One {
return NewMany2One(ru.Id.Get(), "")
}

// CreateResUsers creates a new res.users model and returns its id.
func (c *Client) CreateResUsers(ru *ResUsers) (int64, error) {
return c.Create(ResUsersModel, ru)
Expand Down

0 comments on commit 30f0f81

Please sign in to comment.