Search code examples
postgresqlodoo-11

data loss with (possibly) autovacumn


I have customised the crm module in Odoo 11.

I added in some product lines to calculate planned revenue without having to create a quotation.

The problem i have is that after a period of time - approx 1 day. the data is cleared from the fields in Odoo.

I set the fields correctly using store=True (i think!!)

The other suspect is the autovacumn scheduled action for the postgresql database clearing the data.

How can I ensure that the data remains and if it is up for vacumming, stop this from being garbage collected?

crm_lead.py

x_order_line = fields.One2many(
    "crm.lead.calc.revenue.line",
    "x_order_id",
    string="Product Lines",
    copy=False,
    auto_join=True,
    store=True,
)

x_product_id = fields.Many2one(
    "product.product",
    related="x_order_line.x_product_id",
    string="Product",
    copy=True,
)

calc_revenue_line.py

class CalcRevenue(models.TransientModel):
    """
    This wizard will Calculate the Planned Revenue of the current record in CRM.lead
    """

    _name = "crm.lead.calc.revenue.line"
    _description = "Line Model for Calculating products"

    x_product_id = fields.Many2one(
        "product.product",
        string="Product",
        domain=[("categ_id", "in", ["Accessories", "Final products", "Subscriptions"])],
        change_default=True,
        ondelete="restrict",
        required=True,
        store=True,
    )

    x_product_uom_qty = fields.Float(
        string="Quantity",
        digits=dp.get_precision("Product Unit of Measure"),
        required=True,
        default=1.0,
        store=True,
    )

    x_order_id = fields.Many2one(
        "crm.lead",
        string="Product Lines",
        required=True,
        ondelete="cascade",
        index=True,
        copy=False,
        store=True,
    )

    x_price_unit = fields.Float(
        "Unit Price", digits=dp.get_precision("Product Price"), default=1.0, store=True
    )

Solution

  • I solved this by changing

    class CalcRevenue(models.TransientModel):

    to:

    class CalcRevenue(models.Model):

    I believe the TransientModel was responsible for not saving the data.