Files
goodie/addons/project/models/project_update.go
Marc fad2a37d1c Expand Sale/Purchase/Project + 102 ORM tests — +4633 LOC
Sale (1177→2321 LOC):
- Quotation templates (apply to order, option lines)
- Sales reports (by month, product, customer, salesperson, category)
- Advance payment wizard (delivered/percentage/fixed modes)
- SO cancel wizard, discount wizard
- action_quotation_sent, action_lock/unlock, preview_quotation
- Line computes: invoice_status, price_reduce, untaxed_amount
- Partner extension: sale_order_total

Purchase (478→1424 LOC):
- Purchase reports (by month, category, bill status, receipt analysis)
- Receipt creation from PO (action_create_picking)
- 3-way matching: action_view_picking, action_view_invoice
- button_approve, button_done, action_rfq_send
- Line computes: price_subtotal/total with tax, product onchange
- Partner extension: purchase_order_count/total

Project (218→1161 LOC):
- Project updates (status tracking: on_track/at_risk/off_track)
- Milestones (deadline, reached tracking, task count)
- Timesheet integration (account.analytic.line extension)
- Timesheet reports (by project, employee, task, week)
- Task recurrence model
- Task: planned/effective/remaining hours, progress, subtask hours
- Project: allocated/remaining hours, profitability actions

ORM Tests (102 tests, 0→1257 LOC):
- domain_test.go: 32 tests (compile, operators, AND/OR/NOT, null)
- field_test.go: 15 tests (IsCopyable, SQLType, IsRelational, IsStored)
- model_test.go: 21 tests (NewModel, AddFields, RegisterMethod, ExtendModel)
- domain_parse_test.go: 21 tests (parse Python domain strings)
- sanitize_test.go: 13 tests (false→nil, type conversions)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 23:39:41 +02:00

70 lines
2.2 KiB
Go

package models
import (
"fmt"
"time"
"odoo-go/pkg/orm"
)
// initProjectUpdate registers the project.update model.
// Mirrors: odoo/addons/project/models/project_update.py
//
// class ProjectUpdate(models.Model):
// _name = 'project.update'
// _description = 'Project Update'
// _order = 'date desc'
func initProjectUpdate() {
m := orm.NewModel("project.update", orm.ModelOpts{
Description: "Project Update",
Order: "date desc, id desc",
})
m.AddFields(
orm.Many2one("project_id", "project.project", orm.FieldOpts{
String: "Project", Required: true, OnDelete: orm.OnDeleteCascade, Index: true,
}),
orm.Char("name", orm.FieldOpts{String: "Title", Required: true}),
orm.Selection("status", []orm.SelectionItem{
{Value: "on_track", Label: "On Track"},
{Value: "at_risk", Label: "At Risk"},
{Value: "off_track", Label: "Off Track"},
{Value: "on_hold", Label: "On Hold"},
}, orm.FieldOpts{String: "Status", Required: true, Default: "on_track"}),
orm.Date("date", orm.FieldOpts{String: "Date", Required: true}),
orm.HTML("description", orm.FieldOpts{String: "Description"}),
orm.Many2one("user_id", "res.users", orm.FieldOpts{String: "Author"}),
orm.Float("progress", orm.FieldOpts{String: "Progress (%)"}),
orm.Integer("color", orm.FieldOpts{String: "Color Index"}),
)
// DefaultGet: set date to today, user to current user
m.DefaultGet = func(env *orm.Environment, fields []string) orm.Values {
vals := make(orm.Values)
vals["date"] = time.Now().Format("2006-01-02")
if env.UID() > 0 {
vals["user_id"] = env.UID()
}
return vals
}
// action_open_project: Return an action to open the project.
m.RegisterMethod("action_open_project", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
env := rs.Env()
updateID := rs.IDs()[0]
var projectID int64
err := env.Tx().QueryRow(env.Ctx(),
`SELECT project_id FROM project_update WHERE id = $1`, updateID).Scan(&projectID)
if err != nil {
return nil, fmt.Errorf("project_update: read update %d: %w", updateID, err)
}
return map[string]interface{}{
"type": "ir.actions.act_window",
"res_model": "project.project",
"res_id": projectID,
"view_mode": "form",
"target": "current",
}, nil
})
}