Skip to content

Commit

Permalink
⬆️1️⃣3️⃣ pos_invoice_pay
Browse files Browse the repository at this point in the history
Signed-off-by: Enigma228322 <[email protected]>
  • Loading branch information
Enigma228322 committed Sep 23, 2020
1 parent ff837c7 commit 96ce7e8
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 242 deletions.
2 changes: 1 addition & 1 deletion pos_invoice_pay/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Usage instructions: `<doc/index.rst>`__

Changelog: `<doc/changelog.rst>`__

Tested on Odoo 12.0 7bc849c3a698665d6f2379aa2b8d870c14a6c849
Tested on Odoo 13.0 533f564fa37aa3321bdaaf373dd2eaf7fd23c659
2 changes: 1 addition & 1 deletion pos_invoice_pay/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"pre_init_hook": None,
"post_init_hook": None,
"auto_install": False,
"installable": False,
"installable": True,
"demo_title": "Pay Sale Orders & Invoices over POS",
"demo_addons": [],
"demo_addons_hidden": [],
Expand Down
2 changes: 1 addition & 1 deletion pos_invoice_pay/actions/base_action_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<odoo>
<record id="invoice_update_pos_action" model="base.automation">
<field name="name">Update Invoices</field>
<field name="model_id" ref="account.model_account_invoice" />
<field name="model_id" ref="account.model_account_move" />
<field name="state">code</field>
<field name="code">
record.action_updated_invoice()
Expand Down
85 changes: 42 additions & 43 deletions pos_invoice_pay/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class PosOrder(models.Model):
_inherit = "pos.order"

@api.model
def create_from_ui(self, orders):
def create_from_ui(self, orders, draft=False):
invoices_to_pay = [o for o in orders if o.get("data").get("invoice_to_pay")]
original_orders = [o for o in orders if o not in invoices_to_pay]
res = super(PosOrder, self).create_from_ui(original_orders)
res = super(PosOrder, self).create_from_ui(original_orders, draft=draft)
if invoices_to_pay:
for inv in invoices_to_pay:
self.process_invoice_payment(inv)
Expand All @@ -24,12 +24,14 @@ def create_from_ui(self, orders):
def process_invoice_payment(self, invoice):
for statement in invoice["data"]["statement_ids"]:
inv_id = invoice["data"]["invoice_to_pay"]["id"]
inv_obj = self.env["account.invoice"].browse(inv_id)
journal_id = statement[2]["journal_id"]
journal = self.env["account.journal"].browse(journal_id)
inv_obj = self.env["account.move"].browse(inv_id)
payment_method_id = statement[2]["payment_method_id"]
journal = self.env["pos.payment.method"].browse(payment_method_id)
amount = min(
statement[2]["amount"], # amount payed including change
invoice["data"]["invoice_to_pay"]["residual"], # amount required to pay
invoice["data"]["invoice_to_pay"][
"amount_residual"
], # amount required to pay
)
cashier = invoice["data"]["user_id"]
writeoff_acc_id = False
Expand All @@ -39,7 +41,7 @@ def process_invoice_payment(self, invoice):
"journal_id": journal.id,
"payment_method_id": 1,
"payment_date": invoice["data"]["creation_date"],
"communication": invoice["data"]["invoice_to_pay"]["number"],
# "communication": invoice["data"]["invoice_to_pay"]["number"],
"invoice_ids": [(4, inv_id, None)],
"payment_type": "inbound",
"amount": amount,
Expand All @@ -57,9 +59,9 @@ def process_invoice_payment(self, invoice):
@api.model
def process_invoices_creation(self, sale_order_id):
order = self.env["sale.order"].browse(sale_order_id)
inv_id = order.action_invoice_create()
self.env["account.invoice"].browse(inv_id).action_invoice_open()
return inv_id
inv_id = order._create_invoices(final=True)
inv_id.action_post()
return inv_id.id


class AccountPayment(models.Model):
Expand All @@ -71,32 +73,29 @@ class AccountPayment(models.Model):


class AccountInvoice(models.Model):
_inherit = "account.invoice"
_inherit = "account.move"

def action_updated_invoice(self):
message = {"channel": INV_CHANNEL, "id": self.id}
self.env["pos.config"].search([])._send_to_channel(INV_CHANNEL, message)

@api.model
def get_invoice_lines_for_pos(self, invoice_ids):
res = []
invoice_lines = self.env["account.invoice.line"].search(
[("invoice_id", "in", invoice_ids)]
def get_invoice_lines_for_pos(self, move_ids):
res = self.env["account.move.line"].search_read(
[("mode_id", "in", move_ids)],
[
"id",
"move_id",
"name",
"account",
"product",
"price_unit",
"qty",
"tax",
"discount",
"amount",
],
)
for l in invoice_lines:
line = {
"invoice_id": l.invoice_id.id,
"id": l.id,
"name": l.name,
"account": l.account_id.name,
"product": l.product_id.name,
"price_unit": l.price_unit,
"qty": l.quantity,
"tax": [tax.name or " " for tax in l.invoice_line_tax_ids],
"discount": l.discount,
"amount": l.price_subtotal,
}
res.append(line)
return res

@api.depends("payment_move_line_ids.amount_residual")
Expand Down Expand Up @@ -131,21 +130,21 @@ def get_order_lines_for_pos(self, sale_order_ids):
order_lines = self.env["sale.order.line"].search(
[("order_id", "in", sale_order_ids)]
)
for l in order_lines:
for i in order_lines:
line = {
"order_id": l.order_id.id,
"id": l.id,
"name": l.name,
"product": l.product_id.name,
"uom_qty": l.product_uom_qty,
"qty_delivered": l.qty_delivered,
"qty_invoiced": l.qty_invoiced,
"tax": [tax.name or " " for tax in l.tax_id],
"discount": l.discount,
"subtotal": l.price_subtotal,
"total": l.price_total,
"order_id": i.order_id.id,
"id": i.id,
"name": i.name,
"product": i.product_id.name,
"uom_qty": i.product_uom_qty,
"qty_delivered": i.qty_delivered,
"qty_invoiced": i.qty_invoiced,
"tax": [tax.name or " " for tax in i.tax_id],
"discount": i.discount,
"subtotal": i.price_subtotal,
"total": i.price_total,
"invoiceble": (
(l.qty_delivered > 0) or (l.product_id.invoice_policy == "order")
(i.qty_delivered > 0) or (i.product_id.invoice_policy == "order")
),
}
res.append(line)
Expand Down Expand Up @@ -208,7 +207,7 @@ def action_invoice_payments(self):
"name": _("Invoice Payments"),
"type": "ir.actions.act_window",
"domain": domain,
"res_model": "account.invoice",
"res_model": "account.move",
"view_type": "form",
"view_mode": "tree,form",
}
4 changes: 2 additions & 2 deletions pos_invoice_pay/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ <h2>Need our service?</h2>
-o-transform: rotate(-6deg);
-moz-transform: rotate(-6deg);
-ms-transform: rotate(-6deg);">
Tested on Odoo<br/>12.0 community
Tested on Odoo<br/>13.0 community
</div>
<div style="margin-top: 15px;
position: relative;
Expand All @@ -265,7 +265,7 @@ <h2>Need our service?</h2>
-o-transform: rotate(-7deg);
-moz-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);">
Tested on Odoo<br/>12.0 enterprise
Tested on Odoo<br/>13.0 enterprise
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 96ce7e8

Please sign in to comment.