From 785cfdafb9764b8efb38a3a2be5b79d91d52a2ee Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Fri, 4 Sep 2015 16:25:19 +0200 Subject: [PATCH] [ADD][account_invoice_split_sale] Add auto_init method --- account_invoice_split_sale/__init__.py | 1 + account_invoice_split_sale/models/__init__.py | 3 ++ .../models/sale_order.py | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 account_invoice_split_sale/models/__init__.py create mode 100644 account_invoice_split_sale/models/sale_order.py diff --git a/account_invoice_split_sale/__init__.py b/account_invoice_split_sale/__init__.py index 02baef47b981..a1e27b0338e6 100644 --- a/account_invoice_split_sale/__init__.py +++ b/account_invoice_split_sale/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- from . import wizard +from . import models diff --git a/account_invoice_split_sale/models/__init__.py b/account_invoice_split_sale/models/__init__.py new file mode 100644 index 000000000000..6064afee1782 --- /dev/null +++ b/account_invoice_split_sale/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_order diff --git a/account_invoice_split_sale/models/sale_order.py b/account_invoice_split_sale/models/sale_order.py new file mode 100644 index 000000000000..3c197aa7763b --- /dev/null +++ b/account_invoice_split_sale/models/sale_order.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.cr_context + def _auto_init(self, cr, context=None): + """ hack: pre-create and initialize the picking_policy column so that + the constraint setting will not fail, this is a hack, made necessary + because Odoo tries to set the not-null constraint before + applying default values """ + self._field_create(cr, context=context) + column_data = self._select_column_data(cr) + if 'picking_policy' not in column_data: + default_picking_policy = 'picking_policy' + if default_picking_policy: + cr.execute("""ALTER TABLE "{table}" ADD COLUMN + "picking_policy" + character varying""".format(table=self._table)) + cr.execute("""UPDATE "{table}" SET + picking_policy='direct'""". + format(table=self._table)) + return super(SaleOrder, self)._auto_init(cr, context=context)