feat: Portal, Email Inbound, Discuss + module improvements
- Portal: /my/* routes, signup, password reset, portal user support - Email Inbound: IMAP polling (go-imap/v2), thread matching - Discuss: mail.channel, long-polling bus, DM, unread count - Cron: ir.cron runner (goroutine scheduler) - Bank Import, CSV/Excel Import - Automation (ir.actions.server) - Fetchmail service - HR Payroll model - Various fixes across account, sale, stock, purchase, crm, hr, project Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package models
|
||||
|
||||
import "odoo-go/pkg/orm"
|
||||
import (
|
||||
"log"
|
||||
|
||||
"odoo-go/pkg/orm"
|
||||
)
|
||||
|
||||
// initAccountRecurring registers account.move.recurring — recurring entry templates.
|
||||
// Mirrors: odoo/addons/account/models/account_move.py (recurring entries feature)
|
||||
@@ -113,4 +117,79 @@ func initAccountRecurring() {
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
// _cron_auto_post: cron job that auto-posts draft moves and generates recurring entries.
|
||||
// Mirrors: odoo/addons/account/models/account_move.py _cron_auto_post_draft_entry()
|
||||
//
|
||||
// 1) Find draft account.move entries with auto_post=true and date <= today, post them.
|
||||
// 2) Find recurring entries (state='running') with date_next <= today, generate them.
|
||||
m.RegisterMethod("_cron_auto_post", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
|
||||
// --- Part 1: Auto-post draft moves ---
|
||||
rows, err := env.Tx().Query(env.Ctx(),
|
||||
`SELECT id FROM account_move
|
||||
WHERE auto_post = true AND state = 'draft' AND date <= CURRENT_DATE`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var moveIDs []int64
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
continue
|
||||
}
|
||||
moveIDs = append(moveIDs, id)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
if len(moveIDs) > 0 {
|
||||
moveModelDef := orm.Registry.Get("account.move")
|
||||
if moveModelDef != nil {
|
||||
for _, mid := range moveIDs {
|
||||
moveRS := env.Model("account.move").Browse(mid)
|
||||
if postFn, ok := moveModelDef.Methods["action_post"]; ok {
|
||||
if _, err := postFn(moveRS); err != nil {
|
||||
log.Printf("account: auto-post move %d failed: %v", mid, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Part 2: Generate recurring entries due today ---
|
||||
recRows, err := env.Tx().Query(env.Ctx(),
|
||||
`SELECT id FROM account_move_recurring
|
||||
WHERE state = 'running' AND date_next <= CURRENT_DATE AND active = true`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var recIDs []int64
|
||||
for recRows.Next() {
|
||||
var id int64
|
||||
if err := recRows.Scan(&id); err != nil {
|
||||
continue
|
||||
}
|
||||
recIDs = append(recIDs, id)
|
||||
}
|
||||
recRows.Close()
|
||||
|
||||
if len(recIDs) > 0 {
|
||||
recModelDef := orm.Registry.Get("account.move.recurring")
|
||||
if recModelDef != nil {
|
||||
for _, rid := range recIDs {
|
||||
recRS := env.Model("account.move.recurring").Browse(rid)
|
||||
if genFn, ok := recModelDef.Methods["action_generate"]; ok {
|
||||
if _, err := genFn(recRS); err != nil {
|
||||
log.Printf("account: recurring generate %d failed: %v", rid, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user