Update sale_down_payment

This commit is contained in:
Alexis de Lattre
2019-11-25 17:13:03 +01:00
parent 361f5d3aae
commit 38db0da20a
6 changed files with 107 additions and 2 deletions

View File

@@ -12,9 +12,9 @@
Sale Down Payment
=================
This module adds a link between payment and sale orders. It allows to see advanced payment directly on the sale order form view.
This module adds a link between payments and sale orders. It allows to see down payments directly on the sale order form view.
After processing a bank statement, you can start a wizard to link unreconciled incoming payments to a sale order.
After processing a bank statement, you can start a wizard to link unreconciled incoming payments to a sale order. There is also a button *Register Payment* on the sale order.
This module targets B2B companies that don't want to generate a down payment invoice for an advanced payment.
@@ -29,6 +29,7 @@ This module has been written by Alexis de Lattre from Akretion
'views/account_bank_statement.xml',
'views/sale.xml',
'views/account_move_line.xml',
'views/account_payment.xml',
],
'installable': True,
}

View File

@@ -1,2 +1,3 @@
from . import sale
from . import account_move_line
from . import account_payment

View File

@@ -0,0 +1,59 @@
# Copyright 2019 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo.tools import float_round
class AccountPayment(models.Model):
_inherit = 'account.payment'
sale_id = fields.Many2one('sale.order', string='Sale Order')
def action_validate_invoice_payment(self):
if self.sale_id:
self.post()
else:
return super(AccountPayment, self).\
action_validate_invoice_payment()
def _get_counterpart_move_line_vals(self, invoice=False):
res = super(AccountPayment, self)._get_counterpart_move_line_vals(
invoice=invoice)
if self.sale_id:
res['sale_id'] = self.sale_id.id
return res
class AccountAbstractPayment(models.AbstractModel):
_inherit = "account.abstract.payment"
def default_get(self, fields_list):
res = super(AccountAbstractPayment, self).default_get(fields_list)
if (
self._context.get('active_model') == 'sale.order' and
self._context.get('active_id')):
so = self.env['sale.order'].browse(self._context['active_id'])
res.update({
'amount': so.amount_total,
'currency_id': so.currency_id.id,
'payment_type': 'inbound',
'partner_id': so.partner_invoice_id.commercial_partner_id.id,
'partner_type': 'customer',
'communication': so.name,
'sale_id': so.id,
})
return res
def _compute_payment_amount(self, invoices=None, currency=None):
amount = super(AccountAbstractPayment, self)._compute_payment_amount(
invoices=invoices, currency=currency)
if self.sale_id:
payment_currency = currency
if not payment_currency:
payment_currency = self.sale_id.currency_id
amount = float_round(
self.sale_id.amount_total - self.sale_id.amount_down_payment,
precision_rounding=payment_currency.rounding)
return amount

View File

@@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import float_round
class SaleOrder(models.Model):
@@ -13,6 +14,9 @@ class SaleOrder(models.Model):
readonly=True)
amount_down_payment = fields.Monetary(
compute='_compute_amount_down_payment', string='Down Payment Amount')
# amount_residual : only used to hide 'Register Payment' button
amount_residual = fields.Monetary(
compute='_compute_amount_down_payment', string='Residual')
@api.depends(
'payment_line_ids.credit', 'payment_line_ids.debit',
@@ -36,4 +40,9 @@ class SaleOrder(models.Model):
down_payment -= sale.company_id.currency_id._convert(
pl.balance, sale_currency, sale.company_id,
pl.date)
down_payment = float_round(
down_payment, precision_rounding=sale.currency_id.rounding)
sale.amount_down_payment = down_payment
sale.amount_residual = float_round(
sale.amount_total - down_payment,
precision_rounding=sale.currency_id.rounding)

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_account_payment_sale_form" model="ir.ui.view">
<field name="name">account.payment.sale.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_invoice_form"/>
<field name="arch" type="xml">
<field name="invoice_ids" position="after">
<field name="sale_id" invisible="1"/>
</field>
</field>
</record>
</odoo>

View File

@@ -8,6 +8,14 @@
<odoo>
<record id="sale_account_payment_action" model="ir.actions.act_window">
<field name="name">Register Payment</field>
<field name="res_model">account.payment</field>
<field name="view_mode">form</field>
<field name="view_id" ref="account.view_account_payment_invoice_form"/>
<field name="target">new</field>
</record>
<record id="view_order_form" model="ir.ui.view">
<field name="name">advance_payment.sale.order.form</field>
<field name="model">sale.order</field>
@@ -16,6 +24,7 @@
<notebook position="inside">
<page name="advance_payment" string="Advance Payments">
<field name="payment_line_ids" nolabel="1"/>
<field name="amount_residual" invisible="1"/>
</page>
</notebook>
<field name="amount_total" position="after">
@@ -24,6 +33,9 @@
</div>
<field name="amount_down_payment" nolabel="1" class="oe_subtotal_footer_separator"/>
</field>
<button name="action_cancel" position="before">
<button type="action" name="%(sale_account_payment_action)d" string="Register Payment" attrs="{'invisible': ['|', ('amount_residual', '&lt;=', 0), ('invoice_status', '=', 'invoiced')]}"/>
</button>
</field>
</record>