31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from odoo import models, fields, api
|
|
|
|
|
|
class AccountPayment(models.Model):
|
|
_inherit = 'account.payment'
|
|
|
|
purchase_order_id = fields.Many2one(
|
|
'purchase.order',
|
|
string='Purchase Order',
|
|
domain="[('partner_id', '=', partner_id), ('state', 'in', ('purchase', 'done'))]"
|
|
)
|
|
|
|
is_advance_payment = fields.Boolean(
|
|
string='Is Advance Payment',
|
|
default=False,
|
|
help='Identifies if this payment is an advance payment for a purchase order'
|
|
)
|
|
|
|
@api.onchange('purchase_order_id')
|
|
def _onchange_purchase_order_id(self):
|
|
if self.purchase_order_id:
|
|
self.amount = self.purchase_order_id.amount_residual
|
|
|
|
def action_post(self):
|
|
res = super().action_post()
|
|
# When an advance payment is posted, link it to the purchase order
|
|
for payment in self:
|
|
if payment.is_advance_payment and payment.purchase_order_id:
|
|
# Apply the deposit to the purchase order
|
|
payment.purchase_order_id.action_apply_deposit()
|
|
return res |