Ir al contenido
Menú
Se marcó esta pregunta

In OdooV16, When creating a quotation from an opportunity, I want to populate other fields by default, so I overloaded this method in crm.lead present in sale_crm module:

def _prepare_opportunity_quotation_context(self):
    quotation_context = super(CrmLead, self)._prepare_opportunity_quotation_context()
    # Populate fields here using: quotation_context['field'] = val
    return quotation_context


To write regular fields, e.g., the validity_date, I can do this and it works:

quotation_context['validity_date'] = (date.today() + timedelta(days=1)).isoformat()


However, to fill the One2many order_line field, I've tried several ways and none have worked:


1. Using the classic (0, 0, vals) pattern:

quotation_context['default_order_line'] += [(0, 0, {
    'name': s.name,
    'product_template_id': s.id,
    'product_uom_qty': 1,
    'product_uom': s.uom_id.id,
    'price_unit': 100.0,
}) for s in servs]
# servs is just a list of products

# Logging quotation_context['default_order_line'] before exiting this function gives:
# [(0, 0, {'name': 'MY SERVICE', 'product_template_id': 65, 'product_uom_qty': 1, 'product_uom': 9, 'price_unit': 100.0})]


2. Passing just a list of vals (without the 0,0)


3. Overriding default_get in sale.order

def default_get(self, fields):
    res = super(SaleOrder, self).default_get(fields)

    if 'default_order_line' in self._context:
        res.update({'order_line': self._context['default_order_line']})

    return res


But none have worked, please helpp 🙏


Issue 69641 in Github seems to be about the same (can't provide a link because karma), but there were no answers


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ene 24
5349
0
jun 23
1959
1
dic 22
3254
0
abr 22
2475
1
abr 19
6149