summaryrefslogtreecommitdiff
path: root/fixco_api/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-05-31 09:30:19 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-05-31 09:30:19 +0700
commit507bcbe0482f33c6305549b554463ab6d45cdc17 (patch)
tree80f01989aa2b4eac8db46b63923985667068feb6 /fixco_api/models
parent1e9824d861f2208e1beb477ea8028cd007ecbd89 (diff)
add paid invoice api
Diffstat (limited to 'fixco_api/models')
-rw-r--r--fixco_api/models/__init__.py1
-rw-r--r--fixco_api/models/invoice.py29
-rw-r--r--fixco_api/models/sale.py21
3 files changed, 50 insertions, 1 deletions
diff --git a/fixco_api/models/__init__.py b/fixco_api/models/__init__.py
index 8a0dc04..69c1de8 100644
--- a/fixco_api/models/__init__.py
+++ b/fixco_api/models/__init__.py
@@ -1 +1,2 @@
from . import sale
+from . import invoice
diff --git a/fixco_api/models/invoice.py b/fixco_api/models/invoice.py
new file mode 100644
index 0000000..354d3ea
--- /dev/null
+++ b/fixco_api/models/invoice.py
@@ -0,0 +1,29 @@
+from odoo import models
+
+
+class Invoice(models.Model):
+ _inherit = 'account.move'
+
+ def _register_payment_automatically(self):
+ payment_model = self.env['account.payment']
+
+ for invoice in self:
+ if invoice.state == 'posted' and invoice.amount_residual > 0:
+ payment_vals = {
+ 'payment_type': 'inbound',
+ 'partner_type': 'customer',
+ 'partner_id': invoice.partner_id.id,
+ 'amount': invoice.amount_residual,
+ 'date': invoice.invoice_date,
+ 'journal_id': self.env['account.journal'].search([('type', '=', 'bank')], limit=1).id,
+ 'payment_method_id': self.env.ref('account.account_payment_method_manual_in').id,
+ 'ref': invoice.name,
+ # 'communication': invoice.name,
+ }
+ payment = payment_model.create(payment_vals)
+ payment.action_post()
+
+ # Reconcile payment with invoice
+ (invoice.line_ids + payment.move_id.line_ids) \
+ .filtered(lambda line: line.account_id.reconcile) \
+ .reconcile()
diff --git a/fixco_api/models/sale.py b/fixco_api/models/sale.py
index 4c81fad..5ddd581 100644
--- a/fixco_api/models/sale.py
+++ b/fixco_api/models/sale.py
@@ -1,7 +1,7 @@
from odoo import models
-class SaleOrder(models.Model):
+class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
def api_single_response(self, line):
@@ -23,3 +23,22 @@ class SaleOrder(models.Model):
'discount': line.discount,
}
return data
+
+
+class SaleOrder(models.Model):
+ _inherit = 'sale.order'
+
+ def api_create_invoices(self, sale_order_id):
+ sale_orders = self.env['sale.order'].search([('id', '=', sale_order_id)])
+
+ # if self.advance_payment_method == 'delivered':
+ invoices = sale_orders._create_invoices(final=False)
+ data = []
+ for invoice in invoices:
+ invoice.action_post()
+ data.append({
+ 'invoice_id': invoice.id,
+ 'invoice': invoice.name,
+ 'state': invoice.state
+ })
+ return data