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 (
|
||||
"fmt"
|
||||
|
||||
"odoo-go/pkg/orm"
|
||||
)
|
||||
|
||||
// initAccountAccount registers the chart of accounts.
|
||||
// Mirrors: odoo/addons/account/models/account_account.py
|
||||
@@ -203,3 +207,95 @@ func initAccountFiscalPosition() {
|
||||
orm.Many2many("country_ids", "res.country", orm.FieldOpts{String: "Countries"}),
|
||||
)
|
||||
}
|
||||
|
||||
// initAccountTaxComputes adds computed fields to account.tax for the tax computation engine.
|
||||
// Mirrors: odoo/addons/account/models/account_tax.py
|
||||
//
|
||||
// - is_base_affected: whether this tax's base is affected by previous taxes in the sequence
|
||||
// - repartition_line_ids: combined view of invoice + refund repartition lines
|
||||
func initAccountTaxComputes() {
|
||||
ext := orm.ExtendModel("account.tax")
|
||||
|
||||
ext.AddFields(
|
||||
orm.Boolean("computed_is_base_affected", orm.FieldOpts{
|
||||
String: "Base Affected (Computed)",
|
||||
Compute: "_compute_is_base_affected",
|
||||
Help: "Computed: true when include_base_amount is set on a preceding tax in the same group",
|
||||
}),
|
||||
orm.Char("repartition_line_ids_json", orm.FieldOpts{
|
||||
String: "Repartition Lines (All)",
|
||||
Compute: "_compute_repartition_line_ids",
|
||||
Help: "JSON list of all repartition line IDs (invoice + refund) for the tax engine",
|
||||
}),
|
||||
)
|
||||
|
||||
// _compute_is_base_affected: determines if this tax's base amount should be
|
||||
// influenced by preceding taxes in the same tax group.
|
||||
// Mirrors: odoo/addons/account/models/account_tax.py _compute_is_base_affected()
|
||||
//
|
||||
// A tax is base-affected when:
|
||||
// 1. It belongs to a group tax (has parent_tax_id), AND
|
||||
// 2. Any sibling tax with a lower sequence has include_base_amount=true
|
||||
// Otherwise it falls back to the manual is_base_affected field value.
|
||||
ext.RegisterCompute("computed_is_base_affected", func(rs *orm.Recordset) (orm.Values, error) {
|
||||
env := rs.Env()
|
||||
taxID := rs.IDs()[0]
|
||||
|
||||
var parentID *int64
|
||||
var seq int64
|
||||
var manualFlag bool
|
||||
env.Tx().QueryRow(env.Ctx(),
|
||||
`SELECT parent_tax_id, COALESCE(sequence, 0), COALESCE(is_base_affected, true)
|
||||
FROM account_tax WHERE id = $1`, taxID,
|
||||
).Scan(&parentID, &seq, &manualFlag)
|
||||
|
||||
// If no parent group, use the manual field value
|
||||
if parentID == nil || *parentID == 0 {
|
||||
return orm.Values{"computed_is_base_affected": manualFlag}, nil
|
||||
}
|
||||
|
||||
// Check if any preceding sibling in the group has include_base_amount=true
|
||||
var count int
|
||||
env.Tx().QueryRow(env.Ctx(),
|
||||
`SELECT COUNT(*) FROM account_tax
|
||||
WHERE parent_tax_id = $1 AND sequence < $2
|
||||
AND include_base_amount = true AND id != $3`,
|
||||
*parentID, seq, taxID,
|
||||
).Scan(&count)
|
||||
|
||||
return orm.Values{"computed_is_base_affected": count > 0 || manualFlag}, nil
|
||||
})
|
||||
|
||||
// _compute_repartition_line_ids: collects all repartition line IDs (invoice + refund)
|
||||
// into a JSON array string for the tax computation engine.
|
||||
// Mirrors: odoo/addons/account/models/account_tax.py _compute_repartition_line_ids()
|
||||
ext.RegisterCompute("repartition_line_ids_json", func(rs *orm.Recordset) (orm.Values, error) {
|
||||
env := rs.Env()
|
||||
taxID := rs.IDs()[0]
|
||||
|
||||
rows, err := env.Tx().Query(env.Ctx(),
|
||||
`SELECT id FROM account_tax_repartition_line
|
||||
WHERE tax_id = $1 ORDER BY sequence, id`, taxID)
|
||||
if err != nil {
|
||||
return orm.Values{"repartition_line_ids_json": "[]"}, nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
result := "["
|
||||
first := true
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
continue
|
||||
}
|
||||
if !first {
|
||||
result += ","
|
||||
}
|
||||
result += fmt.Sprintf("%d", id)
|
||||
first = false
|
||||
}
|
||||
result += "]"
|
||||
|
||||
return orm.Values{"repartition_line_ids_json": result}, nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user