Files
goodie/addons/sale/models/init.go
Marc b8fa4719ad Deep dive: Account, Stock, Sale, Purchase — +800 LOC business logic
Account:
- Multi-currency: company_currency_id, amount_total_signed
- Lock dates on res.company (period, fiscal year, tax) + enforcement in action_post
- Recurring entries: account.move.recurring with action_generate (copy+advance)
- Tax groups: amount_type='group' computes child taxes with include_base_amount
- ComputeTaxes batch function, findTaxAccount helper

Stock:
- Lot/Serial tracking: enhanced stock.lot with expiration dates + qty compute
- Routes: stock.route model with product/category/warehouse selectable flags
- Rules: stock.rule model with pull/push/buy/manufacture actions + procure methods
- Returns: action_return on picking (swap locations, copy moves)
- Product tracking extension (none/lot/serial) + route_ids M2M

Sale:
- Pricelist: get_product_price with fixed/percentage/formula computation
- Margin: purchase_price, margin, margin_percent on line + order totals
- Down payments: action_create_down_payment (deposit invoice at X%)

Purchase:
- 3-way matching: action_create_bill now updates qty_invoiced on PO lines
- Purchase agreements: purchase.requisition + line with state machine

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

43 lines
1.2 KiB
Go

package models
import "odoo-go/pkg/orm"
func Init() {
initSaleOrder()
initSaleOrderLine()
initResPartnerSaleExtension()
initSaleMargin()
}
// initResPartnerSaleExtension extends res.partner with sale-specific fields.
// Mirrors: odoo/addons/sale/models/res_partner.py
//
// class ResPartner(models.Model):
// _inherit = 'res.partner'
// sale_order_count = fields.Integer(compute='_compute_sale_order_count')
// sale_order_ids = fields.One2many('sale.order', 'partner_id', string='Sales Orders')
func initResPartnerSaleExtension() {
partner := orm.ExtendModel("res.partner")
partner.AddFields(
orm.One2many("sale_order_ids", "sale.order", "partner_id", orm.FieldOpts{
String: "Sales Orders",
}),
orm.Integer("sale_order_count", orm.FieldOpts{
String: "Sale Order Count",
Compute: "_compute_sale_order_count",
}),
)
partner.RegisterCompute("sale_order_count", func(rs *orm.Recordset) (orm.Values, error) {
env := rs.Env()
partnerID := rs.IDs()[0]
var count int
err := env.Tx().QueryRow(env.Ctx(),
`SELECT COUNT(*) FROM sale_order WHERE partner_id = $1`, partnerID,
).Scan(&count)
if err != nil {
count = 0
}
return orm.Values{"sale_order_count": count}, nil
})
}