From 30f0f81e4a57024be5a1c585c716f237ba81ec55 Mon Sep 17 00:00:00 2001 From: Antoine Huret Date: Thu, 23 Apr 2020 23:52:52 +0200 Subject: [PATCH] add Many2One helper --- README.md | 6 ++++++ account_account.go | 5 +++++ account_analytic_account.go | 5 +++++ account_analytic_line.go | 5 +++++ account_invoice.go | 5 +++++ account_invoice_line.go | 5 +++++ account_journal.go | 5 +++++ generator/cmd/tmpl/model.tmpl | 5 +++++ product_product.go | 5 +++++ product_supplierinfo.go | 5 +++++ project_project.go | 5 +++++ project_task.go | 5 +++++ res_company.go | 5 +++++ res_partner.go | 5 +++++ res_partner_category.go | 5 +++++ res_users.go | 5 +++++ 16 files changed, 81 insertions(+) diff --git a/README.md b/README.md index a081705f..a6730012 100644 --- a/README.md +++ b/README.md @@ -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 : diff --git a/account_account.go b/account_account.go index c77acf7b..b5604564 100644 --- a/account_account.go +++ b/account_account.go @@ -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) diff --git a/account_analytic_account.go b/account_analytic_account.go index 12583ed1..10e0642a 100644 --- a/account_analytic_account.go +++ b/account_analytic_account.go @@ -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) diff --git a/account_analytic_line.go b/account_analytic_line.go index c33bceea..27bb35be 100644 --- a/account_analytic_line.go +++ b/account_analytic_line.go @@ -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) diff --git a/account_invoice.go b/account_invoice.go index f9e32dfc..ec39d006 100644 --- a/account_invoice.go +++ b/account_invoice.go @@ -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) diff --git a/account_invoice_line.go b/account_invoice_line.go index fbd03f28..00f030f8 100644 --- a/account_invoice_line.go +++ b/account_invoice_line.go @@ -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) diff --git a/account_journal.go b/account_journal.go index e0136ffc..9e3e41fc 100644 --- a/account_journal.go +++ b/account_journal.go @@ -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) diff --git a/generator/cmd/tmpl/model.tmpl b/generator/cmd/tmpl/model.tmpl index 8ce90f2a..ba64c07b 100644 --- a/generator/cmd/tmpl/model.tmpl +++ b/generator/cmd/tmpl/model.tmpl @@ -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}}) diff --git a/product_product.go b/product_product.go index 333c58fc..7313d3f5 100644 --- a/product_product.go +++ b/product_product.go @@ -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) diff --git a/product_supplierinfo.go b/product_supplierinfo.go index 779e1361..8663b812 100644 --- a/product_supplierinfo.go +++ b/product_supplierinfo.go @@ -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) diff --git a/project_project.go b/project_project.go index 12d2f138..8d1ee86d 100644 --- a/project_project.go +++ b/project_project.go @@ -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) diff --git a/project_task.go b/project_task.go index 532c396b..79ca10e6 100644 --- a/project_task.go +++ b/project_task.go @@ -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) diff --git a/res_company.go b/res_company.go index 507cb00e..625f95e9 100644 --- a/res_company.go +++ b/res_company.go @@ -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) diff --git a/res_partner.go b/res_partner.go index 7c8fbdad..8bb567be 100644 --- a/res_partner.go +++ b/res_partner.go @@ -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) diff --git a/res_partner_category.go b/res_partner_category.go index 5e2a480c..7f2c345f 100644 --- a/res_partner_category.go +++ b/res_partner_category.go @@ -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) diff --git a/res_users.go b/res_users.go index 787cafec..d5ade617 100644 --- a/res_users.go +++ b/res_users.go @@ -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)