first commit
This commit is contained in:
parent
2e90e4df22
commit
261821dd80
@ -19,6 +19,7 @@ account payable.
|
||||
'data/account_payment_method_data.xml',
|
||||
'views/account_batch_payment_views.xml',
|
||||
'views/account_payment_views.xml',
|
||||
'views/account_payment_register_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import account_batch_payment
|
||||
from . import account_payment
|
||||
from . import account_payment_register
|
||||
45
models/account_payment_register.py
Normal file
45
models/account_payment_register.py
Normal file
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class AccountPaymentRegister(models.TransientModel):
|
||||
_inherit = "account.payment.register"
|
||||
|
||||
# Add expense account field to payment register wizard
|
||||
expense_account_id = fields.Many2one(
|
||||
'account.account',
|
||||
string='Expense Account',
|
||||
domain="[('account_type', 'not in', ('asset_receivable', 'liability_payable'))]",
|
||||
help="Account used for expense instead of the default payable/receivable account"
|
||||
)
|
||||
|
||||
@api.depends('journal_id', 'partner_type', 'is_internal_transfer', 'destination_journal_id', 'expense_account_id')
|
||||
def _compute_destination_account_id(self):
|
||||
''' Override to use expense account if defined '''
|
||||
super()._compute_destination_account_id()
|
||||
for pay in self:
|
||||
# If we have an expense account, use it instead of the default payable/receivable account
|
||||
if pay.expense_account_id and ((pay.payment_type == 'outbound' and pay.partner_type == 'supplier') or
|
||||
(pay.payment_type == 'inbound' and pay.partner_type == 'customer')):
|
||||
pay.destination_account_id = pay.expense_account_id
|
||||
|
||||
def _create_payment_vals_from_wizard(self, batch_result):
|
||||
''' Override to use expense account if defined '''
|
||||
payment_vals = super()._create_payment_vals_from_wizard(batch_result)
|
||||
|
||||
# If we have an expense account, replace the destination account
|
||||
if self.expense_account_id and len(payment_vals.get('line_ids', [])) >= 2:
|
||||
# The second line is typically the counterpart line (payable/receivable)
|
||||
payment_vals['line_ids'][1]['account_id'] = self.expense_account_id.id
|
||||
|
||||
return payment_vals
|
||||
|
||||
def _create_payment_vals_from_batch(self, batch_result):
|
||||
''' Override to use expense account if defined '''
|
||||
payment_vals = super()._create_payment_vals_from_batch(batch_result)
|
||||
|
||||
# If we have an expense account, replace the destination account
|
||||
if self.expense_account_id:
|
||||
payment_vals['destination_account_id'] = self.expense_account_id.id
|
||||
|
||||
return payment_vals
|
||||
@ -1 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import account_batch_payment_views
|
||||
from . import account_payment_views
|
||||
from . import account_payment_register_views
|
||||
15
views/account_payment_register_views.xml
Normal file
15
views/account_payment_register_views.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_account_payment_register_form_inherit" model="ir.ui.view">
|
||||
<field name="name">account.payment.register.form.inherit</field>
|
||||
<field name="model">account.payment.register</field>
|
||||
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='group1']" position="inside">
|
||||
<field name="expense_account_id"
|
||||
invisible="(partner_type != 'supplier' or payment_type != 'outbound') and (partner_type != 'customer' or payment_type != 'inbound')"
|
||||
domain="[('account_type', 'not in', ('asset_receivable', 'liability_payable'))]"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue
Block a user