fix accounting payemnt and budget
This commit is contained in:
parent
df1d3ed392
commit
8c65372d14
|
|
@ -78,6 +78,12 @@ class CrossoveredBudgetLines(models.Model):
|
|||
confirm = fields.Float(string='Confirm Amount', compute='_compute_confirm',
|
||||
help=_('Total amount of confirmed purchase orders'))
|
||||
|
||||
@api.constrains('purchase_remain','amount')
|
||||
def _amount_can_not_be_less_than_zero(self):
|
||||
for rec in self:
|
||||
if rec.purchase_remain < 0 or rec.amount < 0:
|
||||
raise ValidationError(_('''The amount can not be less than zero.'''))
|
||||
|
||||
@api.depends('analytic_account_id')
|
||||
def _compute_confirm(self):
|
||||
for rec in self:
|
||||
|
|
@ -191,19 +197,20 @@ class CrossoveredBudgetLines(models.Model):
|
|||
date_from = self.env.context.get(
|
||||
'wizard_date_from') or line.date_from
|
||||
if line.analytic_account_id.id:
|
||||
analytic_ids = self.env['account.analytic.account'].search(
|
||||
['|', ('id', '=', line.analytic_account_id.id),
|
||||
('parent_id', 'child_of', line.analytic_account_id.id)])
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
SELECT SUM(amount)
|
||||
FROM account_analytic_line
|
||||
WHERE account_id IN %s
|
||||
AND (date between %s AND %s)
|
||||
AND general_account_id=ANY(%s)""",
|
||||
(tuple(analytic_ids.ids), date_from, date_to, acc_ids,))
|
||||
result = self.env.cr.fetchone()[0] or 0.0
|
||||
line.practical_amount = result
|
||||
analytic_ids = self.env['account.move.line'].search(
|
||||
['|', ('analytic_account_id', '=', line.analytic_account_id.id),
|
||||
('analytic_account_id', 'child_of', line.analytic_account_id.id),
|
||||
('account_id', 'in',line.general_budget_id.account_ids.ids),
|
||||
('date', '>=', date_from),
|
||||
('date', '<=', date_to),
|
||||
('move_id.state', '=', 'posted'),
|
||||
('move_id.move_type', '=', 'in_invoice')
|
||||
])
|
||||
total_amount = 0
|
||||
for item in analytic_ids:
|
||||
tax_id = item.tax_ids[0].analytic if item.tax_ids else False
|
||||
total_amount += item.price_subtotal + (item.price_tax if tax_id else 0)
|
||||
line.practical_amount = total_amount * -1
|
||||
else:
|
||||
|
||||
aml_obj = self.env['account.move.line']
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class AccountPayment(models.Model):
|
|||
'A second payment has been created: <a href=# data-oe-model=account.payment data-oe-id=%d>%s</a>') % (
|
||||
paired_payment.id, paired_payment.name)
|
||||
payment.message_post(body=body)
|
||||
|
||||
paired_payment.state='posted'
|
||||
lines = (payment.move_id.line_ids + paired_payment.move_id.line_ids).filtered(
|
||||
lambda l: l.account_id == payment.destination_account_id and not l.reconciled)
|
||||
lines.reconcile()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class BudgetConfirmationCustom(models.Model):
|
|||
self.invoice_id.message_post(body=_(
|
||||
"Rejected By : %s With Reject Reason : %s" % (str(self.env.user.name), str(self.reject_reason or self.env.context.get('reject_reason','')))))
|
||||
|
||||
|
||||
def done(self):
|
||||
super(BudgetConfirmationCustom, self).done()
|
||||
if self.invoice_id and self.type == 'vendor.bill':
|
||||
|
|
@ -60,6 +61,21 @@ class AccountMove(models.Model):
|
|||
is_check = fields.Boolean(defaul=False)
|
||||
is_approve = fields.Boolean(defaul=False)
|
||||
hide_budget = fields.Boolean(defaul=False,copy=False)
|
||||
|
||||
|
||||
def action_open_related_payment_records(self):
|
||||
""" Opens a tree view with related records filtered by a dynamic domain """
|
||||
payments = self.env['account.payment'].search([
|
||||
('invoice_rec_id', '=', self.id)
|
||||
]).ids
|
||||
|
||||
return {
|
||||
'name': _('Payments'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'account.payment',
|
||||
'view_mode': 'tree,form',
|
||||
'domain': [('id', 'in', payments)],
|
||||
}
|
||||
def copy(self):
|
||||
self.write({'budget_check': False})
|
||||
# self.write({'is_check':False})
|
||||
|
|
@ -71,7 +87,8 @@ class AccountMove(models.Model):
|
|||
for rec in self.invoice_line_ids:
|
||||
if rec.analytic_account_id.is_analytic_budget and not rec.analytic_account_id.is_auto_check:
|
||||
self.write({
|
||||
'state': 'confirm'
|
||||
'state': 'confirm',
|
||||
'hide_budget': False
|
||||
})
|
||||
break
|
||||
else:
|
||||
|
|
@ -176,7 +193,7 @@ class AccountMove(models.Model):
|
|||
else:
|
||||
remain = abs(budget_lines[0].remain)
|
||||
tax_id = line.tax_ids[0].analytic if line.tax_ids else False
|
||||
amount = amount + (line.price_subtotal + line.price_tax)
|
||||
amount = amount + (line.price_subtotal + (line.price_tax if tax_id else 0))
|
||||
new_remain = remain - amount
|
||||
confirmation_lines.append((0, 0, {
|
||||
'amount': line.price_subtotal + (line.price_tax if tax_id else 0),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,18 @@
|
|||
<odoo>
|
||||
|
||||
|
||||
<record id="view_budget_analytic_account_form_custom" model="ir.ui.view">
|
||||
<record id="view_account_payment_form" model="ir.ui.view">
|
||||
<field name="name">account.payment.form.custom</field>
|
||||
<field name="model">account.payment</field>
|
||||
<field name="inherit_id" ref="account.view_account_payment_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='is_matched']" position="after">
|
||||
<field name="invoice_rec_id" invisible="1"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_budget_analytic_account_form_custom" model="ir.ui.view">
|
||||
<field name="name">analytic.analytic.account.form.custom</field>
|
||||
<field name="model">account.analytic.account</field>
|
||||
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
|
||||
|
|
@ -15,6 +26,7 @@
|
|||
</record>
|
||||
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="crossovered_budget_view_form_inherit">
|
||||
<field name="name">crossovered.budget.inherit.view.form</field>
|
||||
<field name="model">crossovered.budget</field>
|
||||
|
|
@ -60,8 +72,11 @@
|
|||
</xpath>
|
||||
|
||||
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
||||
<button class="oe_stat_button" name="open_confirmation" type="object" string="Budget Confirmation" attrs="{'invisible': [('move_type', '!=', 'in_invoice')]}"/>
|
||||
</xpath>
|
||||
<button class="oe_stat_button" name="open_confirmation" type="object" string="Budget Confirmation"
|
||||
attrs="{'invisible': [('move_type', '!=', 'in_invoice')]}"/>
|
||||
<button class="oe_stat_button" name="action_open_related_payment_records" type="object"
|
||||
string="Payments" attrs="{'invisible': [('move_type', '!=', 'in_invoice')]}"/>
|
||||
</xpath>
|
||||
|
||||
<button name="button_cancel" position="attributes">
|
||||
<attribute name="attrs">{'invisible' : ['|', ('id', '=', False), ('state', 'not in',
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
from odoo import models,fields
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_inherit = "account.payment"
|
||||
|
||||
invoice_rec_id = fields.Many2one(comodel_name='account.move', string='Invoice', copy=False)
|
||||
|
||||
class AccountPaymentRegister(models.TransientModel):
|
||||
_inherit = 'account.payment.register'
|
||||
|
||||
|
||||
def _create_payments(self):
|
||||
self.ensure_one()
|
||||
active_id = self.env.context.get('active_id')
|
||||
batches = self._get_batches()
|
||||
edit_mode = self.can_edit_wizard and (len(batches[0]['lines']) == 1 or self.group_payment)
|
||||
to_process = []
|
||||
|
|
@ -42,6 +47,7 @@ class AccountPaymentRegister(models.TransientModel):
|
|||
self._reconcile_payments(process_final, edit_mode=edit_mode)
|
||||
for payment in payments:
|
||||
if payment.payment_type == 'outbound':
|
||||
payment.invoice_rec_id = active_id
|
||||
payment.action_cancel()
|
||||
payment.action_draft()
|
||||
return payments
|
||||
|
|
@ -24,7 +24,8 @@ class AccountPayment(models.Model):
|
|||
res = super(AccountPayment, self).create(vals)
|
||||
if res.analytic_account_id and res.move_id:
|
||||
for line in res.move_id.line_ids:
|
||||
line.analytic_account_id = res.analytic_account_id.id
|
||||
if line.account_id.id == res.destination_account_id.id:
|
||||
line.analytic_account_id = res.analytic_account_id.id
|
||||
return res
|
||||
|
||||
def _check_permission(self, group_xml_id):
|
||||
|
|
@ -40,8 +41,8 @@ class AccountPayment(models.Model):
|
|||
payment.state = 'posted'
|
||||
if payment.analytic_account_id and payment.move_id:
|
||||
for line in payment.move_id.line_ids:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
|
||||
if line.account_id.id == payment.destination_account_id.id:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
return res
|
||||
|
||||
def action_cancel(self):
|
||||
|
|
@ -59,7 +60,8 @@ class AccountPayment(models.Model):
|
|||
payment.state = 'cancel'
|
||||
if payment.analytic_account_id and payment.move_id:
|
||||
for line in payment.move_id.line_ids:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
if line.account_id.id == payment.destination_account_id.id:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
return res
|
||||
|
||||
def action_draft(self):
|
||||
|
|
@ -68,7 +70,8 @@ class AccountPayment(models.Model):
|
|||
payment.state = 'draft'
|
||||
if payment.analytic_account_id and payment.move_id:
|
||||
for line in payment.move_id.line_ids:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
if line.account_id.id == payment.destination_account_id.id:
|
||||
line.analytic_account_id = payment.analytic_account_id.id
|
||||
payment.state_history = 'cancel'
|
||||
return res
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<field name="inherit_id" ref="account.view_account_payment_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='move_id']" position="after">
|
||||
<field name="analytic_account_id"/>
|
||||
<field name="analytic_account_id" attrs="{'invisible':[('partner_type','!=','GL')]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
Loading…
Reference in New Issue