Rename module sale_advance_payment_management to sale_down_payment
Add field amount_down_payment on sale.order
This commit is contained in:
2
sale_down_payment/models/__init__.py
Normal file
2
sale_down_payment/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import sale
|
||||
from . import account_move_line
|
||||
32
sale_down_payment/models/account_move_line.py
Normal file
32
sale_down_payment/models/account_move_line.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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 api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
sale_id = fields.Many2one('sale.order', string='Sale Order')
|
||||
account_internal_type = fields.Selection(
|
||||
related='account_id.user_type_id.type', store=True,
|
||||
string='Account Internal Type')
|
||||
|
||||
@api.constrains('sale_id', 'account_id')
|
||||
def sale_id_check(self):
|
||||
for line in self:
|
||||
if line.sale_id and line.account_id.internal_type != 'receivable':
|
||||
raise ValidationError(_(
|
||||
"The account move line '%s' is linked to sale order '%s' "
|
||||
"but it uses account '%s' which is not a receivable "
|
||||
"account.")
|
||||
% (line.name,
|
||||
line.sale_id.name,
|
||||
line.account_id.display_name))
|
||||
|
||||
@api.onchange('account_id')
|
||||
def sale_advance_payement_account_id_change(self):
|
||||
if self.sale_id and self.account_id.user_type_id.type != 'receivable':
|
||||
self.sale_id = False
|
||||
39
sale_down_payment/models/sale.py
Normal file
39
sale_down_payment/models/sale.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# 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 api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
payment_line_ids = fields.One2many(
|
||||
'account.move.line', 'sale_id', string='Advance Payments',
|
||||
readonly=True)
|
||||
amount_down_payment = fields.Monetary(
|
||||
compute='_compute_amount_down_payment', string='Down Payment Amount')
|
||||
|
||||
@api.depends(
|
||||
'payment_line_ids.credit', 'payment_line_ids.debit',
|
||||
'payment_line_ids.amount_currency', 'payment_line_ids.currency_id',
|
||||
'payment_line_ids.date', 'currency_id')
|
||||
def _compute_amount_down_payment(self):
|
||||
for sale in self:
|
||||
down_payment = 0.0
|
||||
sale_currency = sale.pricelist_id.currency_id
|
||||
if sale_currency == sale.company_id.currency_id:
|
||||
for pl in sale.payment_line_ids:
|
||||
down_payment -= pl.balance
|
||||
else:
|
||||
for pl in sale.payment_line_ids:
|
||||
if (
|
||||
pl.currency_id and
|
||||
pl.currency_id == sale_currency and
|
||||
pl.amount_currency):
|
||||
down_payment -= pl.amount_currency
|
||||
else:
|
||||
down_payment -= sale.company_id.currency_id._convert(
|
||||
pl.balance, sale_currency, sale.company_id,
|
||||
pl.date)
|
||||
sale.amount_down_payment = down_payment
|
||||
Reference in New Issue
Block a user