Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): process to generate vat3 kra returns #99

Merged
merged 12 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/csf_ke.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 91 additions & 2 deletions csf_ke/csf_ke/doctype/vat3_returns/test_vat3_returns.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,98 @@
# Copyright (c) 2024, Navari Ltd and Contributors
# See license.txt

# import frappe
import frappe
from frappe.tests.utils import FrappeTestCase
from .vat3_returns import fetch_invoices


class TestVAT3Returns(FrappeTestCase):
pass

def setUp(self):
# test company
self.company = "Test Company"
self.currency = "KES"

self.sales_invoice = frappe.get_doc({
"doctype": "Sales Invoice",
"customer": "Test Customer",
"company": self.company,
"currency": self.currency,
"party_account_currency": self.currency,
"docstatus": 1,
"posting_date": "2024-01-01",
"sales_order": "Test Sales Order",
"is_filed": 0,
"grand_total": 1000
}).insert()

self.purchase_invoice = frappe.get_doc({
"doctype": "Purchase Invoice",
"supplier": "Test Supplier",
"company": self.company,
"currency": self.currency,
"party_account_currency": self.currency,
"docstatus": 1,
"posting_date": "2024-01-01",
"is_filed": 0,
"grand_total": 1000
}).insert()

self.vat3_returns = frappe.get_doc({
"doctype": "VAT3 Returns",
"company": self.company,
"from_date": "2024-01-01",
"to_date": "2024-01-31",
"invoices": [
{
"document_type": "Sales Invoice",
"invoice_number": self.sales_invoice.name,
},
{
"document_type": "Purchase Invoice",
"invoice_number": self.purchase_invoice.name,
}
]
}).insert()


def tearDown(self):
# Clean up test data
frappe.delete_doc("VAT3 Returns", self.vat3_returns.name)
frappe.delete_doc("Sales Invoice", self.sales_invoice.name)
frappe.delete_doc("Purchase Invoice", self.purchase_invoice.name)


def test_mark_invoices_as_filed_on_submit(self):
self.vat3_returns.submit()

self.sales_invoice.reload()
self.assertEqual(self.sales_invoice.is_filed, 1, "Sales Invoice should be filed")

self.purchase_invoice.reload()
self.assertEqual(self.purchase_invoice.is_filed, 1, "Purchase Invoice should be filed")


def test_mark_invoices_as_filed_on_cancel(self):
self.vat3_returns.submit()
self.vat3_returns.cancel()

self.sales_invoice.reload()
self.assertEqual(self.sales_invoice.is_filed, 0, "Sales Invoice should not be filed")

self.purchase_invoice.reload()
self.assertEqual(self.purchase_invoice.is_filed, 0, "Purchase Invoice should not be filed")


def test_fetch_invoices(self):

fetched_invoices = fetched_invoices(
invoice_type="Sales Invoice",
from_date="2024-01-01",
to_date="2024-01-31",
company=self.company
)

self.assertEqual(len(fetched_invoices), 1, "There should be one fetched Sales Invoice")
self.assertEqual(fetched_invoices[0].get("name"), self.sales_invoice.name, "Fetched Sales Invoice should match the created Sales Invoice")

61 changes: 57 additions & 4 deletions csf_ke/csf_ke/doctype/vat3_returns/vat3_returns.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
// Copyright (c) 2024, Navari Ltd and contributors
// For license information, please see license.txt

// frappe.ui.form.on("VAT3 Returns", {
// refresh(frm) {
frappe.ui.form.on("VAT3 Returns", {
buying: function(frm) {
if (frm.doc.buying) {
frm.set_value('selling', 0);
} else {
frm.set_value('selling', 1);
}
},
selling: function(frm) {
if (frm.doc.selling) {
frm.set_value('buying', 0);
} else {
frm.set_value('buying', 1);
}
},
from_date: function(frm){
if (frm.doc.from_date) {
let fromDate = new Date(frm.doc.from_date);
let endOfMonth = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0);
frm.set_value('to_date', endOfMonth.toISOString().split('T')[0]);
}
},
fetch_invoices: function(frm) {

// },
// });
frm.set_df_property('fetch_invoices', 'disabled', true);

frappe.dom.freeze();

frm.clear_table('invoices');

frappe.call({
method: 'fetch_invoices',
doc: frm.doc,
args: {
invoice_type: frm.doc.selling ? "Sales Invoice" : "Purchase Invoice",
from_date: frm.doc.from_date,
to_date: frm.doc.to_date,
company: frm.doc.company
},
callback: function(r) {
frm.refresh_field('invoices');

frm.set_df_property('fetch_invoices', 'disabled', false);

frappe.dom.unfreeze();

},
error: function(err) {
frappe.msgprint(__('There was an error fetching invoices.'));

frm.set_df_property('fetch_invoices', 'disabled', false);

frappe.dom.unfreeze();
}
});
},
});

79 changes: 78 additions & 1 deletion csf_ke/csf_ke/doctype/vat3_returns/vat3_returns.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2024-10-08 08:30:50.441399",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"section_break_gyiq",
"company",
"from_date",
"to_date",
"column_break_gejf",
"selling",
"buying",
"naming_series",
"section_break_lbra",
"fetch_invoices",
"invoices",
"section_break_lvzd",
"amended_from"
],
"fields": [
Expand All @@ -22,18 +34,83 @@
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{
"fieldname": "company",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"fieldname": "column_break_gejf",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_lvzd",
"fieldtype": "Section Break"
},
{
"fieldname": "section_break_lbra",
"fieldtype": "Section Break"
},
{
"depends_on": "eval: doc.to_date;",
"fieldname": "fetch_invoices",
"fieldtype": "Button",
"label": "Fetch Invoices"
},
{
"fieldname": "invoices",
"fieldtype": "Table",
"label": "Invoices",
"options": "VAT3 Returns Invoice"
},
{
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From Date",
"reqd": 1
},
{
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To Date",
"reqd": 1
},
{
"default": "0",
"fieldname": "buying",
"fieldtype": "Check",
"label": "Buying"
},
{
"default": "1",
"fieldname": "selling",
"fieldtype": "Check",
"label": "Selling"
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Series",
"options": "VAT3-.DD.-.MM.-"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-10-08 08:30:50.441399",
"modified": "2024-11-26 10:18:15.264659",
"modified_by": "Administrator",
"module": "CSF KE",
"name": "VAT3 Returns",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
"amend": 1,
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
Expand Down
Loading