-
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
[IMP] api: Add and enhance multiple endpoints for improved functionality #25
base: 15.0
Are you sure you want to change the base?
Conversation
hantec_api_ecommerce/__manifest__.py
Outdated
"installable": True, | ||
"development_status": "Production/Stable", | ||
"maintainers": ["C&O PROJECTS AND SOLUTIONS"], | ||
} |
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.
EOF
} | ||
) | ||
logger.info( | ||
"Scheduled activity created with ID %s for invoice %s", |
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.
do you really need this log?
what about move it as logger.debug
""" | ||
# Delivery address data | ||
shipping_address = order.partner_shipping_id | ||
address_data = { |
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.
better use
shipping_address.read([fields])
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.
this
), | ||
} | ||
|
||
# Get related shipping records |
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.
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
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.
this
- 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
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
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
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
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
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)]) |
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.
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 @ |
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.
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) |
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.
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) |
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.
same, not used
|
||
""" | ||
# Find the invoice | ||
invoice = request.env["account.move"].browse(invoice_id).exists() |
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.
not used
return order.get_shipping_info() | ||
|
||
@route( | ||
"/download_invoice/<int:invoice_id>", methods=["GET"], type="http", auth="user" |
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.
what about to use the model
https://github.com/Vauxoo/addons-vauxoo/blob/15.0/website_sale_brand_catalogs/controllers/portal.py#L10
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.
Do I use this model for a new endpoint? @hugho-ad
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.
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") |
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.
not used location_id
- 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
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
I pushed the new changes, could you please review it ? @hugho-ad |
@@ -0,0 +1,69 @@ | |||
from odoo import models, fields |
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.
from odoo import models, fields | |
from odoo import models |
not used
} | ||
|
||
@route("/delivery_address", methods=["POST"], type="json", auth="user") | ||
def delivery_address(self): |
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.
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): |
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.
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
- 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
I pushed the new changes @hugho-ad |
could you please review it? @hugho-ad |
|
||
if only_create: | ||
address = False | ||
if address: |
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.
if address: | |
if address and not only_create: |
this way we can avoid the if above
LGTM 👍 Just squash again please git rebase --autosquash -i origin/15.0 |
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
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
It is ready @hugho-ad |
one important thing, its the uni tests, did you plan to include them? |
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
…ers and groups management.
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.
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
/create_schedule_activity_invoice
/get_states_mexico
/get_inventory_by_sku
/get_inventory
/send_message_sale_order
/create_schedule_activity
/confirm_sale_order
/send_invoice_by_email/int:invoice_id
/stamp_invoice/int:invoice_id
/download_invoice/int:invoice_id
/get_shipping_info/<model("sale.order"):order>
/register_payment_invoice/<model("account.move"):invoice>
/invoice_sale_order
/update_sale_order
/create_sale_order
/delivery_address
/address_invoice
/update_contact
/create_contact
README.rst
Related PR
Please review the changes and provide feedback. Thank you!