Batch 1 (quick-fixes): - Field.Copy attribute + IsCopyable() method for copy control - Constraints now run in Write() (was only Create — bug fix) - Readonly fields silently skipped in Write() - active_test: auto-filter archived records in Search() Batch 2 (Related field write-back): - preprocessRelatedWrites() follows FK chain and writes to target model - Enables Settings page to edit company name/address/etc. - Loop protection via _write_related_depth context counter Batch 3 (_inherits delegation): - SetupAllInherits() generates Related fields from parent models - preprocessInheritsCreate() auto-creates parent records on Create - Declared on res.users, res.company, product.product - Called in LoadModules before compute setup Batch 4 (Copy method): - Recordset.Copy(defaults) with blacklist, IsCopyable check - M2M re-linking, rec_name "(copy)" suffix - Replaces simplified copy case in server dispatch Batch 5 (Onchange compute): - RunOnchangeComputes() triggers dependent computes on field change - Virtual record (ID=-1) with client values in cache - Integrated into onchange RPC handler Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
package models
|
|
|
|
import "odoo-go/pkg/orm"
|
|
|
|
// initResCompany registers the res.company model.
|
|
// Mirrors: odoo/addons/base/models/res_company.py class Company
|
|
//
|
|
// In Odoo, companies are central to multi-company support.
|
|
// Every record can be scoped to a company via company_id.
|
|
func initResCompany() {
|
|
m := orm.NewModel("res.company", orm.ModelOpts{
|
|
Description: "Companies",
|
|
Order: "sequence, name",
|
|
Inherits: map[string]string{"res.partner": "partner_id"},
|
|
})
|
|
|
|
// -- Identity --
|
|
m.AddFields(
|
|
orm.Char("name", orm.FieldOpts{String: "Company Name", Required: true}),
|
|
orm.Integer("sequence", orm.FieldOpts{String: "Sequence", Default: 10}),
|
|
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
|
orm.Many2one("parent_id", "res.company", orm.FieldOpts{String: "Parent Company"}),
|
|
orm.One2many("child_ids", "res.company", "parent_id", orm.FieldOpts{String: "Child Companies"}),
|
|
)
|
|
|
|
// -- Contact (delegates to partner) --
|
|
// In Odoo: _inherits = {'res.partner': 'partner_id'}
|
|
// We use explicit fields instead of delegation for clarity.
|
|
m.AddFields(
|
|
orm.Many2one("partner_id", "res.partner", orm.FieldOpts{
|
|
String: "Partner", Required: true, OnDelete: orm.OnDeleteRestrict,
|
|
}),
|
|
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"}),
|
|
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"}),
|
|
orm.Char("company_registry", orm.FieldOpts{String: "Company ID (Registry)"}),
|
|
)
|
|
|
|
// -- Currency --
|
|
m.AddFields(
|
|
orm.Many2one("currency_id", "res.currency", orm.FieldOpts{
|
|
String: "Currency", Required: true,
|
|
}),
|
|
)
|
|
|
|
// -- Display --
|
|
m.AddFields(
|
|
orm.Binary("logo", orm.FieldOpts{String: "Company Logo"}),
|
|
orm.Char("color", orm.FieldOpts{String: "Color"}),
|
|
orm.Integer("font_color", orm.FieldOpts{String: "Font Color"}),
|
|
)
|
|
|
|
// -- Report Layout --
|
|
m.AddFields(
|
|
orm.Many2one("paperformat_id", "report.paperformat", orm.FieldOpts{String: "Paper Format"}),
|
|
orm.HTML("report_header", orm.FieldOpts{String: "Company Tagline"}),
|
|
orm.HTML("report_footer", orm.FieldOpts{String: "Report Footer"}),
|
|
)
|
|
|
|
// -- Fiscal --
|
|
m.AddFields(
|
|
orm.Many2one("account_fiscal_country_id", "res.country", orm.FieldOpts{String: "Fiscal Country"}),
|
|
)
|
|
}
|