-
Notifications
You must be signed in to change notification settings - Fork 0
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
add exports module base structure #85
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e4fd9aa
add exports module base structure
NileshPant1999 e0ef404
minor bug fixes and all
NileshPant1999 ebd6717
test fix
NileshPant1999 213dfbb
Merge branch 'bug-fixes-and-cleanup' of https://github.com/fylein/fyl…
NileshPant1999 513b802
Merge branch 'master' of https://github.com/fylein/fyle-sage-desktop-…
NileshPant1999 ccf8717
Merge branch 'master' of https://github.com/fylein/fyle-sage-desktop-…
NileshPant1999 d50834b
minor fixes
NileshPant1999 074b247
comments resolved
NileshPant1999 d64df79
lint fix
NileshPant1999 408a75d
minor change
NileshPant1999 7d60258
resolve master
NileshPant1999 f1e2023
naming fixed
NileshPant1999 ae67de2
add fix
NileshPant1999 73a612f
Purchace invoice and Purchase invoice linitems model (#84)
NileshPant1999 a35e320
Merge branch 'master' of https://github.com/fylein/fyle-sage-desktop-…
NileshPant1999 a8c7a1d
resolve conflitscts
NileshPant1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
def get_sage300_connection_class(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class PurchaceInvoice(): | ||
pass | ||
|
||
|
||
class PurchaceInvoiceLineitems(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import List | ||
from django_q.tasks import Chain | ||
|
||
from apps.accounting_exports.models import AccountingExport | ||
from apps.workspaces.models import FyleCredential | ||
|
||
|
||
def check_accounting_export_and_start_import(self, export_type: str, accounting_exports: List[AccountingExport]): | ||
""" | ||
Check accounting export group and start export | ||
""" | ||
|
||
fyle_credentials = FyleCredential.objects.filter(workspace_id=self.workspace_id) | ||
|
||
chain = Chain() | ||
chain.append('apps.fyle.helpers.sync_dimensions', fyle_credentials, self.workspace_id) | ||
for index, accounting_export_group in enumerate(accounting_exports): | ||
accounting_export, _ = AccountingExport.objects.get_or_create( | ||
workspace_id=accounting_export_group.workspace_id, | ||
id=accounting_export_group.id, | ||
defaults={ | ||
'status': 'ENQUEUED', | ||
'type': export_type | ||
} | ||
) | ||
if accounting_export.status not in ['IN_PROGRESS', 'ENQUEUED']: | ||
accounting_export.status = 'ENQUEUED' | ||
accounting_export.save() | ||
|
||
last_export = False | ||
if accounting_export.count() == index + 1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wont this condition always be false? |
||
last_export = True | ||
|
||
chain.append('apps.sage300.purchace_invoice.queues.create_purchace_invoice', accounting_export, last_export) | ||
|
||
if chain.length() > 1: | ||
chain.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from datetime import datetime | ||
from django.db import transaction | ||
|
||
from apps.accounting_exports.models import AccountingExport | ||
from apps.sage300.exports.purchase_invoice.models import PurchaceInvoice, PurchaceInvoiceLineitems | ||
from apps.workspaces.models import ExportSetting | ||
from apps.sage300.utils import SageDesktopConnector | ||
|
||
|
||
class ExportPurchaceInvoice: | ||
|
||
""" | ||
Class for purchace invoice module | ||
""" | ||
|
||
def __init__( | ||
self, | ||
workspace_id: int, | ||
): | ||
self.workspace_id = workspace_id | ||
|
||
def trigger_import(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export |
||
""" | ||
Trigger import for Project module | ||
""" | ||
self.check_accounting_export_and_start_import() | ||
|
||
def __construct_purchace_invoice(item, lineitem): | ||
pass | ||
|
||
def post_purchace_invoice(self, item, lineitem): | ||
""" | ||
Export Purchace Invoice | ||
""" | ||
|
||
try: | ||
purchace_invoice_payload = self.__construct_purchace_invoice(item, lineitem) | ||
|
||
sage300_connection = SageDesktopConnector() | ||
created_purchace_invoice_ = sage300_connection.connection.documents.post_document(purchace_invoice_payload) | ||
return created_purchace_invoice_ | ||
|
||
except Exception as e: | ||
print(e) | ||
|
||
def create_purchace_invoice(self, accounting_export: AccountingExport): | ||
""" | ||
function to create purchace invoice | ||
""" | ||
|
||
export_settings = ExportSetting.objects.filter(workspace_id=accounting_export.workspace_id) | ||
|
||
if accounting_export.status not in ['IN_PROGRESS', 'COMPLETE']: | ||
accounting_export.status = 'IN_PROGRESS' | ||
accounting_export.save() | ||
else: | ||
return | ||
|
||
try: | ||
with transaction.atomic(): | ||
purchace_invoice_object = PurchaceInvoice.create_expense_report(accounting_export) | ||
|
||
purchace_invoice_lineitems_objects = PurchaceInvoiceLineitems.create_expense_report_lineitems( | ||
accounting_export, export_settings | ||
) | ||
|
||
created_purchace_invoice = self.post_purchace_invoice( | ||
purchace_invoice_object, purchace_invoice_lineitems_objects | ||
) | ||
|
||
accounting_export.detail = created_purchace_invoice | ||
accounting_export.status = 'COMPLETE' | ||
accounting_export.exported_at = datetime.now() | ||
|
||
accounting_export.save() | ||
|
||
except Exception as e: | ||
print(e) | ||
# will add execptions here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import List | ||
|
||
from sage300.exports.purchase_invoice.tasks import PurchaceInvoice | ||
from accounting_exports.models import AccountingExport | ||
|
||
EXPORT_CLASS_MAP = { | ||
'PURCHACE_INVOICE': PurchaceInvoice, | ||
} | ||
|
||
|
||
def trigger_export_via_schedule(workspace_id: int, export_type: str, accounting_exports: List[AccountingExport]): | ||
""" | ||
Trigger import via schedule | ||
:param workspace_id: Workspace id | ||
:param destination_field: Destination field | ||
:param source_field: Type of attribute (e.g., 'PROJECT', 'CATEGORY', 'COST_CENTER') | ||
""" | ||
|
||
module_class = EXPORT_CLASS_MAP[export_type] | ||
item = module_class(workspace_id, accounting_exports) | ||
item.trigger_export() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove