From 8752ff10f5a33bfd3947ce48c7b7fd8f3aa2181d Mon Sep 17 00:00:00 2001 From: Elouan Le Bars Date: Wed, 22 Jan 2020 14:00:14 +0100 Subject: [PATCH] [ADD] b_purchase_manual_date_planned : init for null values --- .../models/purchase.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/beesdoo_purchase_manual_date_planned/models/purchase.py b/beesdoo_purchase_manual_date_planned/models/purchase.py index a438e0f..43d87eb 100644 --- a/beesdoo_purchase_manual_date_planned/models/purchase.py +++ b/beesdoo_purchase_manual_date_planned/models/purchase.py @@ -9,6 +9,23 @@ class PurchaseOrder(models.Model): string="Scheduled Date", required=True ) + def init(self,cr): + cr.execute( + """ + UPDATE purchase_order + SET manual_date_planned = (SELECT date_planned + FROM purchase_order_line + WHERE purchase_order_line.order_id = purchase_order.id + AND purchase_order_line.date_planned IS NOT NULL + LIMIT 1) + """ + ) + cr.execute( + """ + ALTER TABLE purchase_order ALTER COLUMN manual_date_planned SET NOT NULL + """ + ) + @api.onchange("order_line", "order_line.date_planned") def _on_change_manual_date_planned(self): """ @@ -23,7 +40,7 @@ class PurchaseOrder(models.Model): @api.multi def button_confirm(self): """ - Since we hide the button to set the date planned on all line and we + Since we hide the button to set the date planned on all line and we hide them, we call the method to set the date planned on the line at the confirmation """ self.ensure_one()