Merge pull request #5499 from expsa/revert_account_payment_distribution
[REF] odex25_account_accountant, account_payment_distribution: remove module & commented code
This commit is contained in:
commit
f96ac0da5d
|
|
@ -1 +0,0 @@
|
|||
from . import models
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
'name': 'Odex Payment Distribution',
|
||||
'version': '1.0',
|
||||
'description': 'Distribute payment on several accounts',
|
||||
'summary': 'Distribute payment on several accounts',
|
||||
'author': 'Abdurrahman Saber',
|
||||
'website': '',
|
||||
'license': 'LGPL-3',
|
||||
'category': 'Accounting',
|
||||
'depends': ['account'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'reports/template.xml',
|
||||
'views/account_payment_views.xml'
|
||||
],
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
from . import account_payment_line, account_payment, account_move
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
from odoo import models, api
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
if 'line_ids' in vals and self.payment_id:
|
||||
self.payment_id._compute_payment_line_ids()
|
||||
return res
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_inherit = 'account.payment'
|
||||
|
||||
payment_line_ids = fields.One2many('account.payment.line', 'payment_id')
|
||||
partner_type = fields.Selection(
|
||||
selection_add=[
|
||||
('many_entries', 'Many Entries'),
|
||||
('account', 'Account'),
|
||||
('employee', 'employee'),
|
||||
],
|
||||
ondelete={
|
||||
'many_entries': 'set default',
|
||||
'account': 'set default',
|
||||
'employee': 'set default',
|
||||
}
|
||||
)
|
||||
|
||||
sutible_account_ids = fields.Many2many(
|
||||
'account.account',
|
||||
string="Suitable Accounts",
|
||||
compute='_compute_sutible_account_ids',
|
||||
store=False
|
||||
)
|
||||
|
||||
destination_account_id = fields.Many2one(
|
||||
'account.account',
|
||||
domain="[('id', 'in', sutible_account_ids)]"
|
||||
)
|
||||
|
||||
@api.depends('partner_type', 'company_id', 'partner_id', 'payment_type')
|
||||
def _compute_sutible_account_ids(self):
|
||||
for r in self:
|
||||
if r.partner_type == 'account':
|
||||
# إظهار جميع حسابات الشركة
|
||||
company_id = r.company_id.id or self.env.company.id
|
||||
domain = [('company_id', '=', company_id)]
|
||||
r.sutible_account_ids = self.env['account.account'].search(domain)
|
||||
elif r.partner_type == 'employee' and r.payment_type == 'outbound' and r.partner_id:
|
||||
# حالة دفع للموظف - استخدام حساب المدين
|
||||
employee_partner = r.partner_id
|
||||
if employee_partner.property_account_receivable_id:
|
||||
r.sutible_account_ids = employee_partner.property_account_receivable_id
|
||||
else:
|
||||
r.sutible_account_ids = self.env['account.account'].browse()
|
||||
elif r.partner_type == 'employee' and r.payment_type == 'inbound' and r.partner_id:
|
||||
# حالة استلام من الموظف - استخدام حساب الدائن
|
||||
employee_partner = r.partner_id
|
||||
if employee_partner.property_account_payable_id:
|
||||
r.sutible_account_ids = employee_partner.property_account_payable_id
|
||||
else:
|
||||
r.sutible_account_ids = self.env['account.account'].browse()
|
||||
elif r.partner_type in ['customer', 'supplier']:
|
||||
# عرض جميع حسابات الشركة (السلوك الافتراضي كما كان من قبل)
|
||||
company_id = r.company_id.id or self.env.company.id
|
||||
domain = [('company_id', '=', company_id)]
|
||||
r.sutible_account_ids = self.env['account.account'].search(domain)
|
||||
else:
|
||||
r.sutible_account_ids = self.env['account.account'].browse()
|
||||
@api.constrains('payment_line_ids')
|
||||
def _check_payment_line_ids(self):
|
||||
for rec in self:
|
||||
if rec.partner_type == 'many_entries' and not rec.payment_line_ids:
|
||||
raise ValidationError(_('At least one distribution line is required for Many Entries partner type'))
|
||||
|
||||
@api.onchange('payment_line_ids')
|
||||
def _compute_payment_amount_from_distribution(self):
|
||||
self.ensure_one()
|
||||
self.amount = sum(self.payment_line_ids.mapped('amount'))
|
||||
|
||||
def _compute_payment_line_ids(self):
|
||||
for rec in self:
|
||||
if rec.partner_type == 'many_entries':
|
||||
lines_vals_list = []
|
||||
total_amount = 0
|
||||
|
||||
for line in rec.move_id.line_ids.filtered(lambda l: l.credit != 0):
|
||||
lines_vals_list.append(self._get_payment_line_vals_from_aml(line))
|
||||
total_amount += line.credit
|
||||
|
||||
rec.write({
|
||||
'payment_line_ids': [(5, 0)] + [(0, 0, line) for line in lines_vals_list],
|
||||
'amount': total_amount
|
||||
})
|
||||
else:
|
||||
rec.payment_line_ids = False
|
||||
|
||||
def _get_payment_line_vals_from_aml(self, move_line_id):
|
||||
return {
|
||||
'account_id': move_line_id.account_id.id,
|
||||
'label': move_line_id.name,
|
||||
'partner_id': move_line_id.partner_id.id,
|
||||
'analytic_account_id': move_line_id.analytic_account_id.id,
|
||||
'analytic_tag_ids': [(6, 0, move_line_id.analytic_tag_ids.ids)],
|
||||
'amount': move_line_id.credit
|
||||
}
|
||||
|
||||
def _prepare_move_line_default_vals(self, write_off_line_vals=None):
|
||||
res = super()._prepare_move_line_default_vals(write_off_line_vals)
|
||||
|
||||
if self.partner_type == 'many_entries':
|
||||
counterpart_line = None
|
||||
liquidity_accounts = [
|
||||
self.journal_id.payment_debit_account_id.id,
|
||||
self.journal_id.payment_credit_account_id.id
|
||||
]
|
||||
|
||||
# Find the counterpart line (the line that is NOT the liquidity line)
|
||||
for line in res:
|
||||
if line.get('account_id') not in liquidity_accounts:
|
||||
counterpart_line = line
|
||||
break
|
||||
|
||||
if not counterpart_line:
|
||||
return res
|
||||
|
||||
res.remove(counterpart_line)
|
||||
|
||||
counterpart_lines = self._prepare_counterpart_lines(counterpart_line)
|
||||
res.extend(counterpart_lines)
|
||||
|
||||
return res
|
||||
|
||||
def _prepare_counterpart_lines(self, counterpart_line):
|
||||
result = []
|
||||
for line in self.payment_line_ids:
|
||||
# Determine debit/credit based on payment type
|
||||
# For inbound payments: debit the accounts (receiving money)
|
||||
# For outbound payments: credit the accounts (paying money)
|
||||
if self.payment_type == 'inbound':
|
||||
line_debit = line.amount
|
||||
line_credit = 0.0
|
||||
amount_currency = line.amount
|
||||
else: # outbound
|
||||
line_debit = 0.0
|
||||
line_credit = line.amount
|
||||
amount_currency = -line.amount
|
||||
|
||||
result.append({
|
||||
'account_id': line.account_id.id,
|
||||
'partner_id': line.partner_id.id,
|
||||
'debit': line_debit,
|
||||
'credit': line_credit,
|
||||
'currency_id': self.currency_id.id,
|
||||
'amount_currency': amount_currency,
|
||||
'name': line.label or counterpart_line['name'],
|
||||
'date_maturity': self.date,
|
||||
'analytic_account_id': line.analytic_account_id.id,
|
||||
'analytic_tag_ids': [(6, 0, line.analytic_tag_ids.ids)]
|
||||
})
|
||||
return result
|
||||
|
||||
def _prepare_payment_display_name(self):
|
||||
res = super()._prepare_payment_display_name()
|
||||
res.update({
|
||||
'inbound-many_entries': _('Customer Many Entries'),
|
||||
'outbound-many_entries': _('Vendor Many Entries'),
|
||||
'inbound-account': _('Customer Account'),
|
||||
'outbound-account': _('Vendor Account'),
|
||||
})
|
||||
return res
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class AccountPaymentLine(models.Model):
|
||||
_name = 'account.payment.line'
|
||||
_description = 'Payment Line'
|
||||
|
||||
account_id = fields.Many2one('account.account', required=True, string='Account')
|
||||
payment_id = fields.Many2one('account.payment', required=True, ondelete='cascade')
|
||||
label = fields.Char(string='Label')
|
||||
partner_id = fields.Many2one('res.partner', string='Partner')
|
||||
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account')
|
||||
analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags')
|
||||
amount = fields.Monetary(currency_field='currency_id', string='Amount', required=True)
|
||||
currency_id = fields.Many2one(related='payment_id.currency_id', readonly=True)
|
||||
|
||||
# حقول إضافية لتحسين UX
|
||||
account_code = fields.Char(related='account_id.code', readonly=True, string='Account Code')
|
||||
account_name = fields.Char(related='account_id.name', readonly=True, string='Account Name')
|
||||
partner_name = fields.Char(related='partner_id.name', readonly=True, string='Partner Name')
|
||||
|
||||
@api.constrains('amount')
|
||||
def _check_amount(self):
|
||||
for rec in self:
|
||||
if rec.amount <= 0:
|
||||
raise ValidationError(_('Line amount must be greater than 0!'))
|
||||
|
||||
@api.onchange('account_id')
|
||||
def _onchange_account_id(self):
|
||||
"""تحديد الشريك تلقائياً بناءً على الحساب"""
|
||||
if self.account_id and self.payment_id:
|
||||
# إذا كان الحساب له شريك افتراضي، نستخدمه
|
||||
if hasattr(self.account_id, 'partner_id') and self.account_id.partner_id:
|
||||
self.partner_id = self.account_id.partner_id
|
||||
elif self.payment_id.partner_id:
|
||||
# وإلا نستخدم شريك الدفع
|
||||
self.partner_id = self.payment_id.partner_id
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_partner_id(self):
|
||||
"""تحديث التسمية عند تغيير الشريك"""
|
||||
if self.partner_id and not self.label:
|
||||
payment_type_label = _('Payment to') if self.payment_id.payment_type == 'outbound' else _('Receipt from')
|
||||
self.label = f"{payment_type_label} {self.partner_id.name}"
|
||||
|
||||
def name_get(self):
|
||||
"""تحسين عرض السطور في الواجهة"""
|
||||
result = []
|
||||
for record in self:
|
||||
name = f"[{record.account_id.code}] {record.account_id.name}"
|
||||
if record.partner_id:
|
||||
name += f" - {record.partner_id.name}"
|
||||
if record.amount:
|
||||
name += f" ({record.amount:,.2f})"
|
||||
result.append((record.id, name))
|
||||
return result
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<template id="report_payment_receipt_document_inherit" inherit_id="account.report_payment_receipt_document">
|
||||
<xpath expr="//table[@class='table table-sm']" position="after">
|
||||
<!-- نسخة ثانية من الجدول -->
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Invoice Date</th>
|
||||
<th>Invoice Number</th>
|
||||
<th>Reference</th>
|
||||
<th class="text-right">Original Amount</th>
|
||||
<th class="text-right">Amount Paid</th>
|
||||
<th class="text-right">Balance</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="o.move_id._get_reconciled_invoices_partials()" t-as="rec">
|
||||
<t t-set="amount" t-value="rec[1]"/>
|
||||
<t t-set="inv" t-value="rec[2].move_id"/>
|
||||
<t t-if="inv.move_type != 'entry'">
|
||||
<td><span t-field="inv.invoice_date"/></td>
|
||||
<td><span t-field="inv.name"/></td>
|
||||
<td><span t-field="inv.ref"/></td>
|
||||
<td class="text-right"><span t-field="inv.amount_total"/></td>
|
||||
<td class="text-right">
|
||||
<span t-esc="amount" t-options="{'widget': 'monetary', 'display_currency': o.currency_id}"/>
|
||||
</td>
|
||||
<td class="text-right"><span t-field="inv.amount_residual"/></td>
|
||||
</t>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_account_payment_line,account.payment.line,model_account_payment_line,,1,1,1,1
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_account_payment_form" model="ir.ui.view">
|
||||
<field name="name">view.account.payment.form</field>
|
||||
<field name="model">account.payment</field>
|
||||
<field name="inherit_id" ref="account.view_account_payment_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//sheet" position="inside">
|
||||
<notebook>
|
||||
<page name="amount_distribution" string="Distribution"
|
||||
attrs="{'invisible': [('partner_type', '!=', 'many_entries')]}">
|
||||
<field name="payment_line_ids" attrs="{'readonly': [('state', '!=', 'draft')]}">
|
||||
<tree editable="bottom">
|
||||
<field name="account_id" />
|
||||
<field name="label" />
|
||||
<field name="partner_id" />
|
||||
<field name="analytic_account_id" optional="hide" />
|
||||
<field name="analytic_tag_ids" optional="hide" widget="many2many_tags"/>
|
||||
<field name="amount" sum="Total Amount"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='amount']" position="attributes">
|
||||
<attribute name="attrs">{'readonly': ['|', ('state', '!=', 'draft'),
|
||||
('partner_type', '=', 'many_entries')]}</attribute>
|
||||
<attribute name="force_save">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='amount']" position="after">
|
||||
<field name="sutible_account_ids" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='destination_account_id']" position="attributes">
|
||||
<attribute name="attrs">{'readonly': ['|', '|', ('state', '!=', 'draft'),
|
||||
('is_internal_transfer', '=', True), ('partner_type', '=', 'many_entries')],
|
||||
'required': [('partner_type', 'not in', ['many_entries'])],
|
||||
'invisible': [('partner_type', '=', 'many_entries')]}</attribute>
|
||||
<attribute name="required">0</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('partner_type', '=', 'many_entries')]}</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -1,69 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, _,api
|
||||
from odoo import models, fields, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_inherit = "account.payment"
|
||||
|
||||
# partner_type = fields.Selection(
|
||||
# selection_add=[
|
||||
# ('account', 'Account'),
|
||||
# ('employee', 'Employee'),
|
||||
# ('multi_account', 'Multi account'),
|
||||
# ],
|
||||
# ondelete={
|
||||
# 'account': 'set default',
|
||||
# 'employee': 'set default',
|
||||
# 'multi_account': 'set default',
|
||||
# },
|
||||
# tracking=True
|
||||
# )
|
||||
#
|
||||
# destination_account_id = fields.Many2one(
|
||||
# comodel_name='account.account',
|
||||
# string='Destination Account',
|
||||
# store=True, readonly=False,
|
||||
# compute='_compute_destination_account_id',
|
||||
# domain="[('company_id', '=', company_id)]",
|
||||
# check_company=True)
|
||||
|
||||
# @api.depends('journal_id', 'partner_id', 'partner_type', 'is_internal_transfer')
|
||||
# def _compute_destination_account_id(self):
|
||||
# self.destination_account_id = False
|
||||
# for pay in self:
|
||||
# if pay.is_internal_transfer:
|
||||
# pay.destination_account_id = pay.journal_id.company_id.transfer_account_id
|
||||
# elif pay.partner_type == 'customer':
|
||||
# # Receive money from invoice or send money to refund it.
|
||||
# if pay.partner_id:
|
||||
# pay.destination_account_id = pay.partner_id.with_company(
|
||||
# pay.company_id).property_account_receivable_id
|
||||
# else:
|
||||
# pay.destination_account_id = self.env['account.account'].search([
|
||||
# ('company_id', '=', pay.company_id.id),
|
||||
# ('internal_type', '=', 'receivable'),
|
||||
# ('deprecated', '=', False),
|
||||
# ], limit=1)
|
||||
# elif pay.partner_type == 'supplier':
|
||||
# # Send money to pay a bill or receive money to refund it.
|
||||
# if pay.partner_id:
|
||||
# pay.destination_account_id = pay.partner_id.with_company(pay.company_id).property_account_payable_id
|
||||
# else:
|
||||
# pay.destination_account_id = self.env['account.account'].search([
|
||||
# ('company_id', '=', pay.company_id.id),
|
||||
# ('internal_type', '=', 'payable'),
|
||||
# ('deprecated', '=', False),
|
||||
# ], limit=1)
|
||||
#
|
||||
# @api.depends('journal_id', 'partner_id', 'partner_type', 'is_internal_transfer')
|
||||
# def _compute_destination_account_id(self):
|
||||
# for pay in self:
|
||||
# if pay.partner_type == 'account':
|
||||
# pay.destination_account_id = pay.destination_account_id
|
||||
#
|
||||
# return super()._compute_destination_account_id()
|
||||
|
||||
def action_open_manual_reconciliation_widget(self):
|
||||
''' Open the manual reconciliation widget for the current payment.
|
||||
:return: A dictionary representing an action.
|
||||
|
|
|
|||
Loading…
Reference in New Issue