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

[IMP] api: Add and enhance multiple endpoints for improved functionality #25

Open
wants to merge 19 commits into
base: 15.0
Choose a base branch
from

Conversation

JAntonioSalas
Copy link
Collaborator

Summary

This pull request introduces improvements and new features across multiple endpoints to enhance the overall functionality and user experience of the system. The changes include better error handling, more detailed responses, and additional validation.

Changes Included

  1. /create_schedule_activity_invoice

    • Added documentation and improved error handling for creating scheduled activities related to invoices.
  2. /get_states_mexico

    • Enhanced endpoint to retrieve the list of states in Mexico with improved error handling and detailed responses.
  3. /get_inventory_by_sku

    • Updated endpoint to retrieve inventory details based on SKU, ensuring accurate and detailed information is returned.
  4. /get_inventory

    • Improved retrieval of inventory details for all products with a SKU, providing more detailed responses.
  5. /send_message_sale_order

    • Added functionality to post messages to sale orders, with improved logging and error handling.
  6. /create_schedule_activity

    • Enhanced the creation of scheduled activities related to sale orders, including additional validation and detailed responses.
  7. /confirm_sale_order

    • Simplified the process of confirming sale orders, with detailed logging and responses.
  8. /send_invoice_by_email/int:invoice_id

    • Improved the functionality for sending invoices by email, ensuring better user feedback and error handling.
  9. /stamp_invoice/int:invoice_id

    • Enhanced the invoice stamping process, including detailed error messages and success responses.
  10. /download_invoice/int:invoice_id

    • Streamlined the invoice download process to generate and deliver PDFs more efficiently.
  11. /get_shipping_info/<model("sale.order"):order>

    • Added functionality to retrieve detailed shipping information for sale orders, including delivery address details and shipping records.
  12. /register_payment_invoice/<model("account.move"):invoice>

    • Improved the payment registration process for invoices, ensuring accurate logging and error handling.
  13. /invoice_sale_order

    • Enhanced the process of invoicing sale orders, including better handling of invoice creation and posting.
  14. /update_sale_order

    • Improved the update process for sale orders, with better validation and detailed logging.
  15. /create_sale_order

    • Enhanced the creation process for sale orders, with better validation and handling of optional fields.
  16. /delivery_address

    • Improved the process for creating or updating delivery addresses, including better handling of address formatting and validation.
  17. /address_invoice

    • Enhanced the process for creating or updating billing addresses, ensuring better validation and error handling.
  18. /update_contact

    • Improved the contact update process, with better validation and detailed logging.
  19. /create_contact

    • Enhanced the contact creation process with better search logic and validation based on email, phone, or store name.
  20. README.rst

    • README.rst for module documentation

Related PR

Please review the changes and provide feedback. Thank you!

hantec_api_ecommerce/__init__.py Outdated Show resolved Hide resolved
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["C&O PROJECTS AND SOLUTIONS"],
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF

hantec_api_ecommerce/controllers/__init__.py Outdated Show resolved Hide resolved
hantec_api_ecommerce/controllers/main.py Outdated Show resolved Hide resolved
hantec_api_ecommerce/controllers/main.py Outdated Show resolved Hide resolved
hantec_api_ecommerce/controllers/main.py Outdated Show resolved Hide resolved
hantec_api_ecommerce/controllers/main.py Outdated Show resolved Hide resolved
}
)
logger.info(
"Scheduled activity created with ID %s for invoice %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need this log?

what about move it as logger.debug

"""
# Delivery address data
shipping_address = order.partner_shipping_id
address_data = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use
shipping_address.read([fields])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this

),
}

# Get related shipping records
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about to move this logic to the model picking or order itself?

you will need to createa dir
models/sale_order.py

and inside the sale_order.py you create the get method with all this logic, this is in order to separated the controllers and the data models

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this

JAntonioSalas added a commit that referenced this pull request May 21, 2024
- Moved the logic of retrieving shipping information from the controller to the sale.order model to improve code maintainability.

- Added the method get_shipping_info in the sale_order.py model to handle the retrieval of detailed shipping information,
including address and picking data. Updated the controller to call the new model method, ensuring a cleaner and more modular
design.

- Added a route to retrieve states by country, which enhances the flexibility of the application in handling different
countries dynamically. Implemented the get_inventory and get_inventory_by_sku methods in the controller to provide
comprehensive inventory data based on SKUs.

- Ensured that __init__.py and __manifest__ files include EOF.

- Get the sales order through the sales order model.

- Combined get_inventory and get_inventory_by_sku endpoints into a single endpoint in the controller. This unified approach
simplifies the API and improves code maintainability. Implemented logic to handle both GET (all products with SKUs) and
POST (specific product by SKU) requests in the same method.

- Refactored the endpoint for scheduling activities related to invoices to use the invoice.activity_schedule method.

These changes improve the modularity, readability, and maintainability of the codebase, making it easier to manage and
extend in the future.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 21, 2024
Modified the get_inventory endpoint to allow filtering of inventory based on a given location. This enhancement improves
the ability to retrieve inventory details specific to a stock location, providing more targeted and relevant data.

This change ensures that users can query inventory data specific to a particular stock location, enhancing the accuracy and
usefulness of the inventory information provided by the endpoint.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 21, 2024
Modified the get_inventory endpoint to allow filtering of inventory based on a given location for GET requests. This enhancement improves the ability to retrieve inventory details specific to a stock location, providing more targeted and relevant data.

This change ensures that users can query inventory data specific to a particular stock location, enhancing the accuracy and usefulness of the inventory information provided by the endpoint.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 21, 2024
Modified the get_inventory endpoint to allow filtering of inventory based on a given location and optionally by SKU.
This enhancement improves the ability to retrieve inventory details specific to a stock location and a product SKU,
providing more targeted and relevant data.

This change ensures that users can query inventory data specific to a particular stock location and product SKU, enhancing
the accuracy and usefulness of the inventory information provided by the endpoint.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 21, 2024
Modified the get_inventory endpoint to allow filtering of inventory based on a given location and optionally by SKU.
This enhancement improves the ability to retrieve inventory details specific to a stock location and a product SKU,
providing more targeted and relevant data.

This change ensures that users can query inventory data specific to a particular stock location and product SKU, enhancing
the accuracy and usefulness of the inventory information provided by the endpoint.

Closes #25
@JAntonioSalas
Copy link
Collaborator Author

I made the changes, could you please review it @hugho-ad ?


inventory_data = []
for product in products:
quants = request.env["stock.quant"].search([("product_id", "=", product.id), ("location_id", "=", location_id)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
quants = request.env["stock.quant"].search([("product_id", "=", product.id), ("location_id", "=", location_id)])
product.with_context(location=location_id).read(["name", "default_code", "qty_available", "virtual_available"])

Don't need to look for quants

contact_data = data.get("contact_data", {})

if email or phone:
email_pattern = r"^([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*)" # Email pattern to get the value before @
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (140 > 119 characters)

partner_id = data.get("partner_id")
invoice_data = data.get("invoice_data")

partner = env["res.partner"].browse(partner_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

partner_id = data.get("partner_id")
delivery_data = data.get("address_data")
only_create = data.get("only_create", False) # Boolean to omit address update
partner = env["res.partner"].browse(partner_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, not used


"""
# Find the invoice
invoice = request.env["account.move"].browse(invoice_id).exists()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

return order.get_shipping_info()

@route(
"/download_invoice/<int:invoice_id>", methods=["GET"], type="http", auth="user"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I use this model for a new endpoint? @hugho-ad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the actual endpoints, the Idea is that you avoid make always the browse over the id you get from data

Returns:
dict: A dictionary with a message and the inventory details of the products.
"""
location_id = request.jsonrequest.get("location_id") or request.params.get("location_id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used location_id

JAntonioSalas added a commit that referenced this pull request May 21, 2024
- Added model in URL and removed browse search: Updated endpoints to use model binding in the URL, removing the need for browsing by ID. This change improves performance and code readability.
- Code formatting: Applied consistent code formatting to enhance readability and maintainability.
- Improved inventory retrieval: Enhanced the inventory retrieval logic to utilize context and simplify queries.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 21, 2024
Removed unnecessary fields from the shipping_info in the get_shipping_info endpoint. This change simplifies the response structure and improves performance.

Changes:
- Removed specific fields from the shipping_info response to streamline the data returned by the endpoint.

Closes #25
@JAntonioSalas
Copy link
Collaborator Author

I pushed the new changes, could you please review it ? @hugho-ad

@@ -0,0 +1,69 @@
from odoo import models, fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from odoo import models, fields
from odoo import models

not used

}

@route("/delivery_address", methods=["POST"], type="json", auth="user")
def delivery_address(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

you could merge this endpoint at the one above at create_address_invoice

it's the same code, just here are handaling the only_create boolean

my recomendation is to merge them in a sigle method

type="json",
auth="user",
)
def create_schedule_activity_invoice(self, invoice=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, you can merge this method with the above, you can handle them if you do it like this
https://github.com/odoo/odoo/blob/15.0/addons/website_crm_partner_assign/controllers/main.py#L210-L214

se how they handle different records sets by model type

the thing is you can avoid duplicated code

JAntonioSalas added a commit that referenced this pull request May 22, 2024
- Merge the endpoints for scheduling activities for both sale orders and invoices into a single endpoint and merge the endpoints delivery and invoicing address. This refactoring simplifies the API by reducing the number of endpoints and centralizing similar functionalities, enhancing the efficiency and maintainability of our code.

- Remove import unnecessary

Closes #25
@JAntonioSalas
Copy link
Collaborator Author

I pushed the new changes @hugho-ad

@JAntonioSalas
Copy link
Collaborator Author

could you please review it? @hugho-ad


if only_create:
address = False
if address:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if address:
if address and not only_create:

this way we can avoid the if above

@hugho-ad
Copy link
Contributor

LGTM 👍

Just squash again please

git rebase --autosquash -i origin/15.0

JAntonioSalas added a commit that referenced this pull request May 23, 2024
The code now combines the condition 'only_create' and 'address' into a single line, ensuring that an address is only updated if it exists and it is not flagged with the 'only_create' option. This change makes the code easier to read and understand.

Closes #25
JAntonioSalas added a commit that referenced this pull request May 23, 2024
Added docstring, clarified the purpose and improved of multiple endpoints to enhance the user experience and maintain consistency in the application.

1. `/create_schedule_activity_invoice`: Improved error handling for creating scheduled activities related to invoices.
2. `/get_states_mexico`: Enhanced the endpoint to retrieve the list of states in Mexico, including better error handling and more detailed responses.
3. `/get_inventory_by_sku`: Updated the endpoint to retrieve inventory details based on SKU, ensuring accurate and detailed inventory information is returned. Filter inventory by location.
4. `/get_inventory`: Improved the retrieval of inventory details for all products with a SKU, adding more detailed responses. Filter inventory by location.
5. `/send_message_sale_order`: Added functionality to post messages to sale orders, with better logging and error handling.
6. `/create_schedule_activity`: Enhanced the creation of scheduled activities related to sale orders, including additional validation and detailed responses.
7. `/confirm_sale_order`: Simplified the process of confirming sale orders and added detailed logging and responses.
8. `/send_invoice_by_email/<int:invoice_id>`: Improved the functionality for sending invoices by email, ensuring better user feedback and error handling.
9. `/stamp_invoice/<int:invoice_id>`: Enhanced the invoice stamping process, including detailed error messages and success responses.
10. `/download_invoice/<int:invoice_id>`: Streamlined the invoice download process to generate and deliver PDFs more efficiently.
11. `/get_shipping_info/<model("sale.order"):order>`: Added functionality to retrieve detailed shipping information for sale orders, including delivery address details and shipping records.
12. `/register_payment_invoice/<model("account.move"):invoice>`: Improved the payment registration process for invoices, ensuring accurate logging and error handling.
13. `/invoice_sale_order`: Enhanced the process of invoicing sale orders, including better handling of invoice creation and posting.
14. `/update_sale_order`: Improved the update process for sale orders, including validation and detailed logging.
15. `/create_sale_order`: Enhanced the creation process for sale orders with better validation and handling of optional fields.
16. Unify scheduling and address endpoints
17. `/delivery_address`: Improved the process for creating or updating delivery addresses, including better handling of address formatting and validation.
18. `/address_invoice`: Enhanced the process for creating or updating billing addresses, ensuring better validation and error handling.
19. `/update_contact`: Improved the contact update process, including better validation and detailed logging.
20. `/create_contact`: Enhanced the contact creation process with better search logic and validation based on email, phone, or store name (contact name).
21. doc: add README.rst for module documentation
22. Filter inventory by location and SKU
23. Unify scheduling and address endpoints

These changes improve the overall robustness and maintainability of the system by ensuring that each endpoint handles data consistently and provides meaningful feedback to users.

Closes #24
Closes #25
@JAntonioSalas
Copy link
Collaborator Author

It is ready @hugho-ad

@hugho-ad
Copy link
Contributor

@JAntonioSalas

one important thing, its the uni tests, did you plan to include them?

@JAntonioSalas
Copy link
Collaborator Author

I think not at the moment because they need to use those endpoints as soon as possible. @hugho-ad

Added docstring, clarified the purpose and improved of multiple endpoints to enhance the user experience and maintain consistency in the application.

1. `/create_schedule_activity_invoice`: Improved error handling for creating scheduled activities related to invoices.
2. `/get_states_mexico`: Enhanced the endpoint to retrieve the list of states in Mexico, including better error handling and more detailed responses.
3. `/get_inventory_by_sku`: Updated the endpoint to retrieve inventory details based on SKU, ensuring accurate and detailed inventory information is returned. Filter inventory by location.
4. `/get_inventory`: Improved the retrieval of inventory details for all products with a SKU, adding more detailed responses. Filter inventory by location.
5. `/send_message_sale_order`: Added functionality to post messages to sale orders, with better logging and error handling.
6. `/create_schedule_activity`: Enhanced the creation of scheduled activities related to sale orders, including additional validation and detailed responses.
7. `/confirm_sale_order`: Simplified the process of confirming sale orders and added detailed logging and responses.
8. `/send_invoice_by_email/<int:invoice_id>`: Improved the functionality for sending invoices by email, ensuring better user feedback and error handling.
9. `/stamp_invoice/<int:invoice_id>`: Enhanced the invoice stamping process, including detailed error messages and success responses.
10. `/download_invoice/<int:invoice_id>`: Streamlined the invoice download process to generate and deliver PDFs more efficiently.
11. `/get_shipping_info/<model("sale.order"):order>`: Added functionality to retrieve detailed shipping information for sale orders, including delivery address details and shipping records.
12. `/register_payment_invoice/<model("account.move"):invoice>`: Improved the payment registration process for invoices, ensuring accurate logging and error handling.
13. `/invoice_sale_order`: Enhanced the process of invoicing sale orders, including better handling of invoice creation and posting.
14. `/update_sale_order`: Improved the update process for sale orders, including validation and detailed logging.
15. `/create_sale_order`: Enhanced the creation process for sale orders with better validation and handling of optional fields.
16. Unify scheduling and address endpoints
17. `/delivery_address`: Improved the process for creating or updating delivery addresses, including better handling of address formatting and validation.
18. `/address_invoice`: Enhanced the process for creating or updating billing addresses, ensuring better validation and error handling.
19. `/update_contact`: Improved the contact update process, including better validation and detailed logging.
20. `/create_contact`: Enhanced the contact creation process with better search logic and validation based on email, phone, or store name (contact name).
21. doc: add README.rst for module documentation
22. Filter inventory by location and SKU
23. Unify scheduling and address endpoints

These changes improve the overall robustness and maintainability of the system by ensuring that each endpoint handles data consistently and provides meaningful feedback to users.

Closes #24
Closes #25
JAntonioSalas and others added 18 commits July 22, 2024 17:32
This app will help the manager to set the price fix as the product price in sale order, purchase order, invoicing and account price.
Add new optional fields when a sale order is created
Add new optional field when a sale order is created
Add dynamic optional fields when creating a sales order
Remove required field when creating sale order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants