Hi everyone. I have a module similar to a sale, in which I have 3 models, one would be sale, the others are saleline and otherlines, I want that when a saleline is created I create a line in otherlines with the same product, where otherlines is a “set” of the products of salelines. The problem is when I edit the create method of saleline I don’t have how to make reference to the sale, this is None. The code is the following:
class Sale(ModelSQL, ModelView):
__name__ = 'sale.sale'
lines = fields.One2Many('sale.line', 'sale', 'Lines')
otherlines = fields.One2Many('sale.otherline', 'sale', 'Other Lines', readonly=True)
class SaleLine(sequence_ordered(), ModelSQL, ModelView):
__name__ = 'sale.line'
sale = fields.Many2One('sale.sale', 'Sale', ondelete='CASCADE', select=True, required=True,)
@classmethod
def create(cls, vlist):
pool = Pool()
SaleOtherLine = pool.get('sale.otherline')
for values in vlist:
if values.get('product'):
other_line = SaleOtherLine()
other_line.product = values['product']
other_line.sale = values['sale'] # this value is None
other_line.save()
return super(SaleLine, cls).create(vlist)
class SaleOtherLine(ModelSQL, ModelView):
__name__ = 'sale.otherline'
sale = fields.Many2One("sale.sale", string = "Sale")
product = fields.Many2One("product.product", string = 'Product')
Thanks in advance.