[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:
@@ -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)
|
||||
|
||||
@@ -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}"/>
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user