Skip to content

Commit 30f0f81

Browse files
author
Antoine Huret
committed
add Many2One helper
1 parent 5a523ce commit 30f0f81

16 files changed

+81
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func (c *Client) FindCrmLead(criteria *Criteria) (*CrmLead, error) {}
107107
func (c *Client) FindCrmLeads(criteria *Criteria, options *Options) (*CrmLeads, error) {}
108108
```
109109

110+
### Conversion
111+
Generated models can be converted to `Many2One` easily.
112+
```go
113+
func (cl *CrmLead) Many2One() *Many2One {}
114+
```
115+
110116
## Types
111117

112118
The library contains custom types to improve the usability :

account_account.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ type AccountAccounts []AccountAccount
3636
// AccountAccountModel is the odoo model name
3737
const AccountAccountModel = "account.account"
3838

39+
// Many2One convert AccountAccount to *Many2One.
40+
func (aa *AccountAccount) Many2One() *Many2One {
41+
return NewMany2One(aa.Id.Get(), "")
42+
}
43+
3944
// CreateAccountAccount creates a new account.account model and returns its id.
4045
func (c *Client) CreateAccountAccount(aa *AccountAccount) (int64, error) {
4146
return c.Create(AccountAccountModel, aa)

account_analytic_account.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type AccountAnalyticAccounts []AccountAnalyticAccount
4848
// AccountAnalyticAccountModel is the odoo model name
4949
const AccountAnalyticAccountModel = "account.analytic.account"
5050

51+
// Many2One convert AccountAnalyticAccount to *Many2One.
52+
func (aaa *AccountAnalyticAccount) Many2One() *Many2One {
53+
return NewMany2One(aaa.Id.Get(), "")
54+
}
55+
5156
// CreateAccountAnalyticAccount creates a new account.analytic.account model and returns its id.
5257
func (c *Client) CreateAccountAnalyticAccount(aaa *AccountAnalyticAccount) (int64, error) {
5358
return c.Create(AccountAnalyticAccountModel, aaa)

account_analytic_line.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ type AccountAnalyticLines []AccountAnalyticLine
4949
// AccountAnalyticLineModel is the odoo model name
5050
const AccountAnalyticLineModel = "account.analytic.line"
5151

52+
// Many2One convert AccountAnalyticLine to *Many2One.
53+
func (aal *AccountAnalyticLine) Many2One() *Many2One {
54+
return NewMany2One(aal.Id.Get(), "")
55+
}
56+
5257
// CreateAccountAnalyticLine creates a new account.analytic.line model and returns its id.
5358
func (c *Client) CreateAccountAnalyticLine(aal *AccountAnalyticLine) (int64, error) {
5459
return c.Create(AccountAnalyticLineModel, aal)

account_invoice.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ type AccountInvoices []AccountInvoice
102102
// AccountInvoiceModel is the odoo model name
103103
const AccountInvoiceModel = "account.invoice"
104104

105+
// Many2One convert AccountInvoice to *Many2One.
106+
func (ai *AccountInvoice) Many2One() *Many2One {
107+
return NewMany2One(ai.Id.Get(), "")
108+
}
109+
105110
// CreateAccountInvoice creates a new account.invoice model and returns its id.
106111
func (c *Client) CreateAccountInvoice(ai *AccountInvoice) (int64, error) {
107112
return c.Create(AccountInvoiceModel, ai)

account_invoice_line.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type AccountInvoiceLines []AccountInvoiceLine
4848
// AccountInvoiceLineModel is the odoo model name
4949
const AccountInvoiceLineModel = "account.invoice.line"
5050

51+
// Many2One convert AccountInvoiceLine to *Many2One.
52+
func (ail *AccountInvoiceLine) Many2One() *Many2One {
53+
return NewMany2One(ail.Id.Get(), "")
54+
}
55+
5156
// CreateAccountInvoiceLine creates a new account.invoice.line model and returns its id.
5257
func (c *Client) CreateAccountInvoiceLine(ail *AccountInvoiceLine) (int64, error) {
5358
return c.Create(AccountInvoiceLineModel, ail)

account_journal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type AccountJournals []AccountJournal
5555
// AccountJournalModel is the odoo model name
5656
const AccountJournalModel = "account.journal"
5757

58+
// Many2One convert AccountJournal to *Many2One.
59+
func (aj *AccountJournal) Many2One() *Many2One {
60+
return NewMany2One(aj.Id.Get(), "")
61+
}
62+
5863
// CreateAccountJournal creates a new account.journal model and returns its id.
5964
func (c *Client) CreateAccountJournal(aj *AccountJournal) (int64, error) {
6065
return c.Create(AccountJournalModel, aj)

generator/cmd/tmpl/model.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ type {{.StructName}}s []{{.StructName}}
1515
// {{.StructName}}Model is the odoo model name
1616
const {{.StructName}}Model = "{{ .Name }}"
1717

18+
// Many2One convert {{.StructName}} to *Many2One.
19+
func ({{.VarName}} *{{.StructName}}) Many2One() *Many2One {
20+
return NewMany2One({{.VarName}}.Id.Get(), "")
21+
}
22+
1823
// Create{{.StructName}} creates a new {{ .Name }} model and returns its id.
1924
func (c *Client) Create{{.StructName}}({{.VarName}} *{{.StructName}}) (int64, error) {
2025
return c.Create({{.StructName}}Model, {{.VarName}})

product_product.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ type ProductProducts []ProductProduct
132132
// ProductProductModel is the odoo model name
133133
const ProductProductModel = "product.product"
134134

135+
// Many2One convert ProductProduct to *Many2One.
136+
func (pp *ProductProduct) Many2One() *Many2One {
137+
return NewMany2One(pp.Id.Get(), "")
138+
}
139+
135140
// CreateProductProduct creates a new product.product model and returns its id.
136141
func (c *Client) CreateProductProduct(pp *ProductProduct) (int64, error) {
137142
return c.Create(ProductProductModel, pp)

product_supplierinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ type ProductSupplierinfos []ProductSupplierinfo
3636
// ProductSupplierinfoModel is the odoo model name
3737
const ProductSupplierinfoModel = "product.supplierinfo"
3838

39+
// Many2One convert ProductSupplierinfo to *Many2One.
40+
func (ps *ProductSupplierinfo) Many2One() *Many2One {
41+
return NewMany2One(ps.Id.Get(), "")
42+
}
43+
3944
// CreateProductSupplierinfo creates a new product.supplierinfo model and returns its id.
4045
func (c *Client) CreateProductSupplierinfo(ps *ProductSupplierinfo) (int64, error) {
4146
return c.Create(ProductSupplierinfoModel, ps)

0 commit comments

Comments
 (0)