Full port of Odoo's ERP system from Python to Go, with the original Odoo JavaScript frontend (OWL framework) running against the Go server. Backend (10,691 LoC Go): - Custom ORM: CRUD, domains→SQL with JOINs, computed fields, sequences - 93 models across 14 modules (base, account, sale, stock, purchase, hr, project, crm, fleet, product, l10n_de, google_address/translate/calendar) - Auth with bcrypt + session cookies - Setup wizard (company, SKR03 chart, admin, demo data) - Double-entry bookkeeping constraint - Sale→Invoice workflow (confirm SO → generate invoice → post) - SKR03 chart of accounts (110 accounts) + German taxes (USt/VSt) - Record rules (multi-company filter) - Google integrations as opt-in modules (Maps, Translate, Calendar) Frontend: - Odoo's original OWL webclient (503 JS modules, 378 XML templates) - JS transpiled via Odoo's js_transpiler (ES modules → odoo.define) - SCSS compiled to CSS (675KB) via dart-sass - XML templates compiled to registerTemplate() JS calls - Static file serving from Odoo source addons - Login page, session management, menu navigation - Contacts list view renders with real data from PostgreSQL Infrastructure: - 14MB single binary (CGO_ENABLED=0) - Docker Compose (Go server + PostgreSQL 16) - Zero phone-home (no outbound calls to odoo.com) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
159 lines
6.3 KiB
Go
159 lines
6.3 KiB
Go
package models
|
|
|
|
import "odoo-go/pkg/orm"
|
|
|
|
// initResPartner registers the res.partner model.
|
|
// Mirrors: odoo/addons/base/models/res_partner.py class Partner(models.Model)
|
|
//
|
|
// res.partner is the central contact model in Odoo. It stores:
|
|
// - Companies and individuals
|
|
// - Customers, vendors, employees (via type)
|
|
// - Addresses (street, city, zip, country)
|
|
// - Communication (email, phone, website)
|
|
func initResPartner() {
|
|
m := orm.NewModel("res.partner", orm.ModelOpts{
|
|
Description: "Contact",
|
|
Order: "name, id",
|
|
RecName: "name",
|
|
})
|
|
|
|
// -- Identity --
|
|
m.AddFields(
|
|
orm.Char("name", orm.FieldOpts{String: "Name", Required: true, Index: true}),
|
|
orm.Char("display_name", orm.FieldOpts{String: "Display Name", Compute: "_compute_display_name", Store: true}),
|
|
orm.Char("ref", orm.FieldOpts{String: "Reference", Index: true}),
|
|
orm.Selection("type", []orm.SelectionItem{
|
|
{Value: "contact", Label: "Contact"},
|
|
{Value: "invoice", Label: "Invoice Address"},
|
|
{Value: "delivery", Label: "Delivery Address"},
|
|
{Value: "other", Label: "Other Address"},
|
|
{Value: "private", Label: "Private Address"},
|
|
}, orm.FieldOpts{String: "Address Type", Default: "contact"}),
|
|
orm.Boolean("is_company", orm.FieldOpts{String: "Is a Company", Default: false}),
|
|
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
|
orm.Char("lang", orm.FieldOpts{String: "Language", Default: "en_US"}),
|
|
orm.Char("tz", orm.FieldOpts{String: "Timezone"}),
|
|
)
|
|
|
|
// -- Address --
|
|
m.AddFields(
|
|
orm.Char("street", orm.FieldOpts{String: "Street"}),
|
|
orm.Char("street2", orm.FieldOpts{String: "Street2"}),
|
|
orm.Char("zip", orm.FieldOpts{String: "Zip"}),
|
|
orm.Char("city", orm.FieldOpts{String: "City"}),
|
|
orm.Many2one("state_id", "res.country.state", orm.FieldOpts{String: "State"}),
|
|
orm.Many2one("country_id", "res.country", orm.FieldOpts{String: "Country"}),
|
|
)
|
|
|
|
// -- Communication --
|
|
m.AddFields(
|
|
orm.Char("email", orm.FieldOpts{String: "Email"}),
|
|
orm.Char("phone", orm.FieldOpts{String: "Phone"}),
|
|
orm.Char("mobile", orm.FieldOpts{String: "Mobile"}),
|
|
orm.Char("website", orm.FieldOpts{String: "Website"}),
|
|
orm.Char("vat", orm.FieldOpts{String: "Tax ID", Index: true}),
|
|
)
|
|
|
|
// -- Company --
|
|
m.AddFields(
|
|
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company", Index: true}),
|
|
orm.Char("company_name", orm.FieldOpts{String: "Company Name"}),
|
|
orm.Char("company_registry", orm.FieldOpts{String: "Company Registry"}),
|
|
)
|
|
|
|
// -- Relationships --
|
|
m.AddFields(
|
|
orm.Many2one("parent_id", "res.partner", orm.FieldOpts{String: "Related Company", Index: true}),
|
|
orm.One2many("child_ids", "res.partner", "parent_id", orm.FieldOpts{String: "Contact & Addresses"}),
|
|
orm.Many2many("category_ids", "res.partner.category", orm.FieldOpts{String: "Tags"}),
|
|
orm.Many2one("user_id", "res.users", orm.FieldOpts{String: "Salesperson"}),
|
|
orm.Many2one("title", "res.partner.title", orm.FieldOpts{String: "Title"}),
|
|
)
|
|
|
|
// -- Commercial --
|
|
m.AddFields(
|
|
orm.Many2one("commercial_partner_id", "res.partner", orm.FieldOpts{
|
|
String: "Commercial Entity", Compute: "_compute_commercial_partner", Store: true,
|
|
}),
|
|
orm.Selection("customer_rank", []orm.SelectionItem{
|
|
{Value: "0", Label: "None"},
|
|
{Value: "1", Label: "Customer"},
|
|
}, orm.FieldOpts{String: "Customer Rank", Default: "0"}),
|
|
orm.Selection("supplier_rank", []orm.SelectionItem{
|
|
{Value: "0", Label: "None"},
|
|
{Value: "1", Label: "Vendor"},
|
|
}, orm.FieldOpts{String: "Vendor Rank", Default: "0"}),
|
|
)
|
|
|
|
// -- Banking --
|
|
m.AddFields(
|
|
orm.One2many("bank_ids", "res.partner.bank", "partner_id", orm.FieldOpts{String: "Bank Accounts"}),
|
|
)
|
|
|
|
// -- Notes --
|
|
m.AddFields(
|
|
orm.Text("comment", orm.FieldOpts{String: "Notes"}),
|
|
orm.Binary("image_1920", orm.FieldOpts{String: "Image"}),
|
|
)
|
|
|
|
// --- Supporting models ---
|
|
|
|
// res.partner.category — Contact tags
|
|
// Mirrors: odoo/addons/base/models/res_partner.py class PartnerCategory
|
|
cat := orm.NewModel("res.partner.category", orm.ModelOpts{
|
|
Description: "Contact Tag",
|
|
Order: "name",
|
|
})
|
|
cat.AddFields(
|
|
orm.Char("name", orm.FieldOpts{String: "Tag Name", Required: true}),
|
|
orm.Integer("color", orm.FieldOpts{String: "Color Index"}),
|
|
orm.Many2one("parent_id", "res.partner.category", orm.FieldOpts{String: "Parent Category"}),
|
|
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
|
)
|
|
|
|
// res.partner.title — Contact titles (Mr., Mrs., etc.)
|
|
// Mirrors: odoo/addons/base/models/res_partner.py class PartnerTitle
|
|
title := orm.NewModel("res.partner.title", orm.ModelOpts{
|
|
Description: "Partner Title",
|
|
Order: "name",
|
|
})
|
|
title.AddFields(
|
|
orm.Char("name", orm.FieldOpts{String: "Title", Required: true, Translate: true}),
|
|
orm.Char("shortcut", orm.FieldOpts{String: "Abbreviation", Translate: true}),
|
|
)
|
|
|
|
// res.partner.bank — Bank accounts
|
|
// Mirrors: odoo/addons/base/models/res_bank.py class ResPartnerBank
|
|
bank := orm.NewModel("res.partner.bank", orm.ModelOpts{
|
|
Description: "Bank Accounts",
|
|
Order: "id",
|
|
RecName: "acc_number",
|
|
})
|
|
bank.AddFields(
|
|
orm.Char("acc_number", orm.FieldOpts{String: "Account Number", Required: true}),
|
|
orm.Char("sanitized_acc_number", orm.FieldOpts{String: "Sanitized Account Number", Compute: "_compute_sanitized"}),
|
|
orm.Many2one("partner_id", "res.partner", orm.FieldOpts{String: "Account Holder", Required: true, OnDelete: orm.OnDeleteCascade}),
|
|
orm.Many2one("bank_id", "res.bank", orm.FieldOpts{String: "Bank"}),
|
|
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
|
orm.Char("acc_holder_name", orm.FieldOpts{String: "Account Holder Name"}),
|
|
)
|
|
|
|
// res.bank — Bank directory
|
|
resBank := orm.NewModel("res.bank", orm.ModelOpts{
|
|
Description: "Bank",
|
|
Order: "name",
|
|
})
|
|
resBank.AddFields(
|
|
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
|
orm.Char("bic", orm.FieldOpts{String: "Bank Identifier Code", Index: true}),
|
|
orm.Char("street", orm.FieldOpts{String: "Street"}),
|
|
orm.Char("street2", orm.FieldOpts{String: "Street2"}),
|
|
orm.Char("zip", orm.FieldOpts{String: "Zip"}),
|
|
orm.Char("city", orm.FieldOpts{String: "City"}),
|
|
orm.Many2one("country", "res.country", orm.FieldOpts{String: "Country"}),
|
|
orm.Char("email", orm.FieldOpts{String: "Email"}),
|
|
orm.Char("phone", orm.FieldOpts{String: "Phone"}),
|
|
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
|
)
|
|
}
|