From ccda3c7734945bf99d8af3e666df93d4bb5ab788 Mon Sep 17 00:00:00 2001 From: Rodia Date: Sun, 27 Jul 2025 00:15:32 -0300 Subject: [PATCH] fix: Update 7.6 --- sale.py | 43 +++++++++++++++++++++++++++++++++++-------- statement.py | 4 ++-- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/sale.py b/sale.py index 7e1a94f..fc003cf 100644 --- a/sale.py +++ b/sale.py @@ -2,6 +2,7 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from decimal import Decimal +from sql import For, Literal from sql.operators import And from sql.aggregate import Sum from sql.conditionals import Coalesce @@ -84,6 +85,16 @@ class Sale(metaclass=PoolMeta): Invoice.write(*invoices) return list(to_post) + @classmethod + @ModelView.button + def process(cls, sales): + states = {'confirmed', 'processing', 'done'} + sales = [s for s in sales if s.state in states] + cls._process_invoice(sales) + cls._process_shipment(sales) + cls._process_invoice_shipment_states(sales) + cls._process_state(sales) + @classmethod def workflow_to_end(cls, sales): pool = Pool() @@ -99,13 +110,16 @@ class Sale(metaclass=PoolMeta): cls.process([sale]) if not sale.invoices and sale.invoice_method == 'order': - raise UserError(gettext( - 'sale_payment.not_customer_invoice', - reference=sale.reference)) + raise UserError( + gettext( + 'sale_payment.not_customer_invoice', + reference=sale.reference + )) to_post = cls.set_invoices_to_be_posted(sales) if to_post: - Invoice.post(to_post) + with Transaction().set_context(_skip_warnings=True): + Invoice.post(to_post) to_save = [] to_do = [] @@ -339,10 +353,23 @@ class WizardSalePayment(Wizard): ) def transition_pay_(self): - Sale = Pool().get('sale.sale') + pool = Pool() + Sale = pool.get('sale.sale') + sale = Sale(Transaction().context['active_id']) + transaction = Transaction() + database = transaction.database + connection = transaction.connection - active_id = Transaction().context.get('active_id', False) - sale = Sale(active_id) + if database.has_select_for(): + table = Sale.__table__() + query = table.select( + Literal(1), + where=(table.id == sale.id), + for_=For('UPDATE', nowait=True)) + with connection.cursor() as cursor: + cursor.execute(*query) + else: + Sale.lock() line = self.get_statement_line(sale) if line: @@ -350,7 +377,7 @@ class WizardSalePayment(Wizard): if sale.total_amount != sale.paid_amount: return 'start' - if sale.state != 'draft': + if sale.state not in ('draft', 'quotation', 'confirmed'): return 'end' sale.description = sale.reference diff --git a/statement.py b/statement.py index 7f30ff4..211548a 100644 --- a/statement.py +++ b/statement.py @@ -408,8 +408,8 @@ class StatementLine(ModelView): if company: return Company(company).currency.id - - @fields.depends('end_balance', 'real_cash', 'mismatch') + @fields.depends( + 'end_balance', 'real_cash', 'mismatch') def on_change_real_cash(self): if self.real_cash and self.end_balance: self.mismatch = self.real_cash - self.end_balance