Hello I have the following class :
class BonDeCommande(models.Model):
_inherit = 'purchase.order'
history = fields.Many2one('app.purch.order.line', string='Historique')
# Overwrite from onchange partner method
@api.onchange('partner_id', 'company_id')
def onchange_partner_id(self):
if not self.partner_id:
self.fiscal_position_id = False
self.payment_term_id = False
self.currency_id = False
else:
self.fiscal_position_id = self.env['account.fiscal.position'].with_context(
company_id=self.company_id.id).get_fiscal_position(self.partner_id.id)
self.payment_term_id = self.partner_id.property_supplier_payment_term_id.id
self.currency_id = self.partner_id.property_purchase_currency_id.id or self.env.user.company_id.currency_id.id
# Link properties between tables
for i in self.env['app.catalogue.liste.catalogue'].search([('supplier', '=', self.partner_id.id)]):
# Create an array of object for different lines
lines = []
for line in i.liste_id:
# get values and converte date
good_date = fields.Date.from_string(self.date_order)
get_date = (good_date + datetime.timedelta(hours=2)).strftime("%x")
hist = dict()
for j in self.env['purchase.order.line'].search([('product_id', '=', line.product.id)]):
hist[j.date_order] = j.product_qty
print hist
new_line = {
'order_id': False,
'product_id': line.product.id,
'name': line.product.name,
'product_qty': line.quantity,
'date_planned': i.date_to,
'product_uom': 1,
'price_unit': line.price,
'history': hist
}
lines.append((0, 0, new_line))
# print lines
# Check if the lines exists
if not self.order_line:
print 'vider ...... \n'
self.order_line = lines
else:
print 'remplir .... \n'
self.order_line = lines
return {}
And :
class PurchOrderLine(models.Model):
_inherit = 'purchase.order.line'
_rec_name = 'history'
history = fields.Char(string='Historique')
The result I get in my history field is this one :
{'2020-10-16 12:21:46': 9.0, '2020-10-14 13:21:56': 6.0}
Which is correct, but it display it as a Char.... So I suppose I must reverse my fields. But the problem is if I did it my Many2one is through purchase.order and I get all the fields and not only my history one as i expect.
Do you have any ideas how I could display the dict object in a correct way for a selection.
Thx