[IMP] pre-commit: first run on whole repo

This commit is contained in:
Kevin Khao
2021-11-26 18:54:38 +03:00
parent a04b8980e1
commit 167aefee13
289 changed files with 6020 additions and 4170 deletions

View File

@@ -2,31 +2,34 @@
# @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 import _, api, fields, models
from odoo.exceptions import ValidationError
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
_inherit = "account.move.line"
sale_id = fields.Many2one('sale.order', string='Sale Order')
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')
related="account_id.user_type_id.type",
store=True,
string="Account Internal Type",
)
@api.constrains('sale_id', 'account_id')
@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))
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')
@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':
if self.sale_id and self.account_id.user_type_id.type != "receivable":
self.sale_id = False

View File

@@ -7,22 +7,22 @@ from odoo.tools import float_round
class AccountPayment(models.Model):
_inherit = 'account.payment'
_inherit = "account.payment"
sale_id = fields.Many2one('sale.order', string='Sale Order')
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()
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)
invoice=invoice
)
if self.sale_id:
res['sale_id'] = self.sale_id.id
res["sale_id"] = self.sale_id.id
return res
@@ -31,29 +31,33 @@ class AccountAbstractPayment(models.AbstractModel):
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,
})
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)
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)
precision_rounding=payment_currency.rounding,
)
return amount

View File

@@ -7,21 +7,27 @@ from odoo.tools import float_round
class SaleOrder(models.Model):
_inherit = 'sale.order'
_inherit = "sale.order"
payment_line_ids = fields.One2many(
'account.move.line', 'sale_id', string='Advance Payments',
readonly=True)
"account.move.line", "sale_id", string="Advance Payments", readonly=True
)
amount_down_payment = fields.Monetary(
compute='_compute_amount_down_payment', string='Down Payment Amount')
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')
compute="_compute_amount_down_payment", string="Residual"
)
@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')
"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
@@ -32,17 +38,20 @@ class SaleOrder(models.Model):
else:
for pl in sale.payment_line_ids:
if (
pl.currency_id and
pl.currency_id == sale_currency and
pl.amount_currency):
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)
pl.balance, sale_currency, sale.company_id, pl.date
)
down_payment = float_round(
down_payment, precision_rounding=sale.currency_id.rounding)
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)
precision_rounding=sale.currency_id.rounding,
)