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:
Marc
2026-04-12 18:41:57 +02:00
parent 2c7c1e6c88
commit 66383adf06
87 changed files with 14696 additions and 654 deletions

View File

@@ -124,6 +124,42 @@ func initSaleOrderTemplate() {
numDays, int64(orderID))
}
// Copy template options as sale.order.option records on the SO
optRows, err := env.Tx().Query(env.Ctx(),
`SELECT COALESCE(name, ''), product_id, COALESCE(quantity, 1),
COALESCE(price_unit, 0), COALESCE(discount, 0), COALESCE(sequence, 10)
FROM sale_order_template_option
WHERE sale_order_template_id = $1 ORDER BY sequence`, templateID)
if err == nil {
optionModel := orm.Registry.Get("sale.order.option")
if optionModel != nil {
optionRS := env.Model("sale.order.option")
for optRows.Next() {
var oName string
var oProdID *int64
var oQty, oPrice, oDisc float64
var oSeq int
if err := optRows.Scan(&oName, &oProdID, &oQty, &oPrice, &oDisc, &oSeq); err != nil {
continue
}
optVals := orm.Values{
"order_id": int64(orderID),
"name": oName,
"quantity": oQty,
"price_unit": oPrice,
"discount": oDisc,
"sequence": oSeq,
"is_present": false,
}
if oProdID != nil {
optVals["product_id"] = *oProdID
}
optionRS.Create(optVals)
}
}
optRows.Close()
}
return true, nil
})
@@ -290,3 +326,94 @@ func initSaleOrderTemplateOption() {
return result
})
}
// initSaleOrderOption registers sale.order.option — optional products on a specific sale order.
// When a template with options is applied to an SO, options are copied here.
// The customer or salesperson can then choose to add them as order lines.
// Mirrors: odoo/addons/sale_management/models/sale_order_option.py SaleOrderOption
func initSaleOrderOption() {
m := orm.NewModel("sale.order.option", orm.ModelOpts{
Description: "Sale Order Option",
Order: "sequence, id",
})
m.AddFields(
orm.Many2one("order_id", "sale.order", orm.FieldOpts{
String: "Sale Order", Required: true, OnDelete: orm.OnDeleteCascade, Index: true,
}),
orm.Many2one("product_id", "product.product", orm.FieldOpts{
String: "Product", Required: true,
}),
orm.Char("name", orm.FieldOpts{String: "Description", Required: true}),
orm.Float("quantity", orm.FieldOpts{String: "Quantity", Default: 1}),
orm.Many2one("uom_id", "uom.uom", orm.FieldOpts{String: "Unit of Measure"}),
orm.Float("price_unit", orm.FieldOpts{String: "Unit Price"}),
orm.Float("discount", orm.FieldOpts{String: "Discount (%)"}),
orm.Integer("sequence", orm.FieldOpts{String: "Sequence", Default: 10}),
orm.Boolean("is_present", orm.FieldOpts{
String: "Present on Order", Default: false,
}),
)
// Onchange: product_id → name + price_unit
m.RegisterOnchange("product_id", func(env *orm.Environment, vals orm.Values) orm.Values {
result := make(orm.Values)
var productID int64
switch v := vals["product_id"].(type) {
case int64:
productID = v
case float64:
productID = int64(v)
case map[string]interface{}:
if id, ok := v["id"]; ok {
switch n := id.(type) {
case float64:
productID = int64(n)
case int64:
productID = n
}
}
}
if productID <= 0 {
return result
}
var name string
var listPrice float64
err := env.Tx().QueryRow(env.Ctx(),
`SELECT COALESCE(pt.name, ''), COALESCE(pt.list_price, 0)
FROM product_product pp
JOIN product_template pt ON pt.id = pp.product_tmpl_id
WHERE pp.id = $1`, productID,
).Scan(&name, &listPrice)
if err != nil {
return result
}
result["name"] = name
result["price_unit"] = listPrice
return result
})
// button_add: Add this option as an order line. Delegates to sale.order action_add_option.
m.RegisterMethod("button_add", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
env := rs.Env()
optionID := rs.IDs()[0]
var orderID int64
err := env.Tx().QueryRow(env.Ctx(),
`SELECT COALESCE(order_id, 0) FROM sale_order_option WHERE id = $1`, optionID,
).Scan(&orderID)
if err != nil || orderID == 0 {
return nil, fmt.Errorf("sale_option: no order linked to option %d", optionID)
}
soRS := env.Model("sale.order").Browse(orderID)
soModel := orm.Registry.Get("sale.order")
if fn, ok := soModel.Methods["action_add_option"]; ok {
return fn(soRS, float64(optionID))
}
return nil, fmt.Errorf("sale_option: action_add_option not found on sale.order")
})
}