mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] sale_payment_web: add field to enter only positive amounts in wizard
This commit is contained in:
committed by
Cedric Collins
parent
f428be93cc
commit
d1a686c13f
@@ -1,6 +1,5 @@
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
|
||||
|
||||
class AccountPaymentRegister(models.TransientModel):
|
||||
@@ -15,6 +14,9 @@ class AccountPaymentRegister(models.TransientModel):
|
||||
company_id = fields.Many2one('res.company') # technical requirement for acquirer domain
|
||||
partner_id = fields.Many2one('res.partner') # technical payment mode/token domain
|
||||
|
||||
currency_id = fields.Many2one(related='journal_id.currency_id')
|
||||
amount = fields.Monetary('Amount')
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
# super implementation checks active_ids, but not active_model
|
||||
@@ -35,6 +37,8 @@ class AccountPaymentRegister(models.TransientModel):
|
||||
raise UserError('Your partner must have an Account Receivable setup.')
|
||||
if 'sale_order_ids' not in rec:
|
||||
rec['sale_order_ids'] = [(6, 0, sale_orders.ids)]
|
||||
if 'amount' not in rec:
|
||||
rec['amount'] = sum(sale_orders.mapped('amount_total'))
|
||||
if 'company_id' not in rec:
|
||||
rec['company_id'] = sale_orders[0].company_id.id
|
||||
if 'partner_id' not in rec:
|
||||
@@ -81,7 +85,8 @@ class AccountPaymentRegister(models.TransientModel):
|
||||
documents.
|
||||
:return: The payment values as a dictionary.
|
||||
'''
|
||||
amount = sum(sale_orders.mapped('amount_total'))
|
||||
if self.amount <= 0:
|
||||
raise UserError("You must enter a positive amount.")
|
||||
values = {
|
||||
'journal_id': self.journal_id.id,
|
||||
'payment_method_id': self.payment_method_id.id,
|
||||
@@ -89,8 +94,8 @@ class AccountPaymentRegister(models.TransientModel):
|
||||
'communication': self._prepare_communication_sale_orders(sale_orders),
|
||||
# TODO sale orders need to get to transactions somehow
|
||||
# 'invoice_ids': [(6, 0, invoices.ids)],
|
||||
'payment_type': ('inbound' if amount > 0 else 'outbound'),
|
||||
'amount': abs(amount),
|
||||
'payment_type': 'inbound', #if amount can be negative we need to allow this to be outbound
|
||||
'amount': self.amount,
|
||||
'currency_id': sale_orders[0].currency_id.id,
|
||||
'partner_id': sale_orders[0].partner_id.id,
|
||||
'partner_type': 'customer',
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
<field name="partner_id" invisible="1" />
|
||||
<field name="payment_token_id" nocreate="1" />
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='payment_date']" position="after">
|
||||
<field name="currency_id" invisible="True"/>
|
||||
<field name="amount"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user