[IMP] sale: make confirmation_date required for confirmed SO

Somehow, when a sales order is confirmed, its confirmation date might not be set (or it is
possible to remove it). This makes no sense as we expect it to be set when the SO is confirmed.
This commit adds an SQL constraint to ensure the confirmation date is required when the SO is
confirmed or done.
To populate this column, the confirmation can be deduced from the mail.message, with the confirmed
subtype.

Task-1930506

closes odoo/odoo#33230

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
This commit is contained in:
jem-odoo
2019-05-07 14:05:35 +00:00
parent a38dc1ccb9
commit 58bcd394ca
3 changed files with 8 additions and 4 deletions
+5 -1
View File
@@ -198,6 +198,10 @@ class SaleOrder(models.Model):
authorized_transaction_ids = fields.Many2many('payment.transaction', compute='_compute_authorized_transaction_ids',
string='Authorized Transactions', copy=False, readonly=True)
_sql_constraints = [
('confirmation_date_conditional_required', "CHECK( (state IN ('sale', 'done') AND confirmation_date IS NOT NULL) OR state NOT IN ('sale', 'done') )", "A confirmed sales order requires a confirmation date."),
]
@api.depends('pricelist_id', 'date_order', 'company_id')
def _compute_currency_rate(self):
for order in self:
@@ -221,7 +225,7 @@ class SaleOrder(models.Model):
"""
for order in self:
dates_list = []
confirm_date = fields.Datetime.from_string((order.confirmation_date or order.write_date) if order.state == 'sale' else fields.Datetime.now())
confirm_date = fields.Datetime.from_string(order.confirmation_date if order.state in ['sale', 'done'] else fields.Datetime.now())
for line in order.order_line.filtered(lambda x: x.state != 'cancel' and not x._is_delivery()):
dt = confirm_date + timedelta(days=line.customer_lead or 0.0)
dates_list.append(dt)
+1 -1
View File
@@ -289,7 +289,7 @@
</group>
<group>
<field name="validity_date" attrs="{'invisible': [('state', 'in', ['sale', 'done'])]}"/>
<field name="confirmation_date" attrs="{'invisible': [('state', 'in', ['draft', 'sent', 'cancel'])]}"/>
<field name="confirmation_date" attrs="{'invisible': [('state', 'in', ['draft', 'sent', 'cancel'])], 'required': [('state', 'in', ['sale', 'done'])]}"/>
<field name="pricelist_id" groups="product.group_sale_pricelist"/>
<field name="currency_id" invisible="1"/>
<field name="payment_term_id" options="{'no_create': True}"/>
+2 -2
View File
@@ -48,7 +48,7 @@ class SaleOrder(models.Model):
super(SaleOrder, self)._compute_expected_date()
for order in self:
dates_list = []
confirm_date = fields.Datetime.from_string((order.confirmation_date or order.write_date) if order.state == 'sale' else fields.Datetime.now())
confirm_date = fields.Datetime.from_string(order.confirmation_date if order.state in ['sale', 'done'] else fields.Datetime.now())
for line in order.order_line.filtered(lambda x: x.state != 'cancel' and not x._is_delivery()):
dt = confirm_date + timedelta(days=line.customer_lead or 0.0)
dates_list.append(dt)
@@ -301,7 +301,7 @@ class SaleOrderLine(models.Model):
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
# When modifying a one2many, _origin doesn't guarantee that its values will be the ones
# When modifying a one2many, _origin doesn't guarantee that its values will be the ones
# in database. Hence, we need to explicitly read them from there.
if self._origin:
product_uom_qty_origin = self._origin.read(["product_uom_qty"])[0]["product_uom_qty"]