-
Notifications
You must be signed in to change notification settings - Fork 84
Multiple branchs option in odoo #2322
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,27 @@ def save_client_details( | |
| ) | ||
| return record | ||
|
|
||
| @staticmethod | ||
| def save_branch_details(bot: str, branch_name: str, company_id: int, user: str, pos_type: POSType = POSType.odoo.value): | ||
| record = POSClientDetails.objects(bot=bot, pos_type=POSType.odoo.value).first() | ||
| if not record: | ||
| raise AppException("No POS client configuration found for this bot.") | ||
| data = record.to_mongo().to_dict() | ||
| client_name = data["client_name"] | ||
| branch_details = { | ||
| "branch_name": branch_name.strip(), | ||
| "company_id": company_id | ||
| } | ||
|
|
||
| record = POSClientDetails.objects( | ||
| bot=bot, | ||
| client_name=client_name | ||
| ).update_one( | ||
| push__branches=branch_details | ||
| ) | ||
|
|
||
| return record | ||
|
|
||
| @staticmethod | ||
| def get_client_details(bot: str): | ||
| """ | ||
|
|
@@ -494,7 +515,7 @@ def jsonrpc_get_uid(self, session_id: str) -> int: | |
| kwargs={"limit": 1} | ||
| )[0] | ||
|
|
||
| def create_pos_order(self, session_id: str, products: list, partner_id: int = None): | ||
| def create_pos_order(self, session_id: str, products: list, partner_id: int = None, company_id: int = 1): | ||
| """ | ||
| Create POS order using JSON-RPC (create_from_ui) | ||
| with check for available_in_pos for every product. | ||
|
|
@@ -579,15 +600,20 @@ def create_pos_order(self, session_id: str, products: list, partner_id: int = No | |
| model="pos.config", | ||
| method="search_read", | ||
| args=[[["active", "=", True]]], | ||
| kwargs={"limit": 1} | ||
| kwargs={ | ||
| "fields": ["id", "company_id"] | ||
| } | ||
| ) | ||
|
|
||
| if not pos_configs: | ||
| raise AppException("No POS Config found") | ||
|
|
||
| config = pos_configs[0] | ||
| config_id = config["id"] | ||
| company_id = config["company_id"][0] if config.get("company_id") else False | ||
| config_id = None | ||
| for config in pos_configs: | ||
| comp_id = config["company_id"][0] if config.get("company_id") else False | ||
| if company_id == comp_id: | ||
| config_id = config["id"] | ||
| break | ||
|
|
||
| open_session = self.jsonrpc_call( | ||
| session_id=session_id, | ||
|
|
@@ -602,9 +628,11 @@ def create_pos_order(self, session_id: str, products: list, partner_id: int = No | |
| kwargs={"limit": 1} | ||
| ) | ||
|
|
||
| payment_method_ids=[] | ||
| if open_session: | ||
| session_id_odoo = open_session[0]["id"] | ||
| sequence_number = open_session[0].get("sequence_number", 1) | ||
| payment_method_ids = open_session[0].get("payment_method_ids", []) | ||
| else: | ||
| session_id_odoo = self.jsonrpc_call( | ||
| session_id=session_id, | ||
|
|
@@ -622,27 +650,19 @@ def create_pos_order(self, session_id: str, products: list, partner_id: int = No | |
|
|
||
| sequence_number = 1 | ||
|
|
||
| pay_method = self.jsonrpc_call( | ||
| session_id=session_id, | ||
| model="pos.payment.method", | ||
| method="search_read", | ||
| args=[[["is_cash_count", "=", True]]], | ||
| kwargs={"limit": 1} | ||
| ) | ||
|
|
||
| if not pay_method: | ||
| pay_method = self.jsonrpc_call( | ||
| if not payment_method_ids: | ||
| payment_method_ids = self.jsonrpc_call( | ||
| session_id=session_id, | ||
| model="pos.payment.method", | ||
| method="search_read", | ||
| args=[[[]]], | ||
| kwargs={"limit": 1} | ||
| ) | ||
|
|
||
| if not pay_method: | ||
| if not payment_method_ids: | ||
| raise HTTPException(status_code=400, detail="No POS payment methods found") | ||
|
|
||
| payment_method_id = pay_method[0]["id"] | ||
| payment_method_id = payment_method_ids[0] | ||
|
Comment on lines
+653
to
+665
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. Type mismatch: When fetching payment methods via 🐛 Proposed fix if not payment_method_ids:
payment_method_ids = self.jsonrpc_call(
session_id=session_id,
model="pos.payment.method",
method="search_read",
args=[[[]]],
- kwargs={"limit": 1}
+ kwargs={"fields": ["id"], "limit": 1}
)
+ if payment_method_ids:
+ payment_method_ids = [pm["id"] for pm in payment_method_ids]
if not payment_method_ids:
raise HTTPException(status_code=400, detail="No POS payment methods found")
payment_method_id = payment_method_ids[0]🤖 Prompt for AI Agents |
||
|
|
||
| order_data = { | ||
| "name": f"POS/{int(time.time())}", | ||
|
|
@@ -680,6 +700,74 @@ def create_pos_order(self, session_id: str, products: list, partner_id: int = No | |
|
|
||
| return {"order_id": order_id, "status": "created"} | ||
|
|
||
| def create_branch(self, session_id: str, branch_name: str, street: str, city: str, state: str, bot: str, user: str): | ||
| INDIA_STATE_MAP = { | ||
| "Andaman and Nicobar": 577, | ||
| "Andhra Pradesh": 578, | ||
| "Arunachal Pradesh": 579, | ||
| "Assam": 580, | ||
| "Bihar": 581, | ||
| "Chattisgarh": 583, | ||
| "Chandigarh": 582, | ||
| "Daman and Diu": 585, | ||
| "Delhi": 586, | ||
| "Dadra and Nagar Haveli": 584, | ||
| "Goa": 587, | ||
| "Gujarat": 588, | ||
| "Himachal Pradesh": 590, | ||
| "Haryana": 589, | ||
| "Jharkhand": 592, | ||
| "Jammu and Kashmir": 591, | ||
| "Karnataka": 593, | ||
| "Kerala": 594, | ||
| "Lakshadweep": 595, | ||
| "Maharashtra": 597, | ||
| "Meghalaya": 599, | ||
| "Manipur": 598, | ||
| "Madhya Pradesh": 596, | ||
| "Mizoram": 600, | ||
| "Nagaland": 601, | ||
| "Odisha": 602, | ||
| "Punjab": 604, | ||
| "Puducherry": 603, | ||
| "Rajasthan": 605, | ||
| "Sikkim": 606, | ||
| "Tamil Nadu": 607, | ||
| "Tripura": 609, | ||
| "Telangana": 608, | ||
| "Uttarakhand": 611, | ||
| "Uttar Pradesh": 610, | ||
| "West Bengal": 612 | ||
| } | ||
| try: | ||
| state_id = INDIA_STATE_MAP[state] | ||
| except KeyError: | ||
| raise HTTPException(status_code=400, detail=f"Invalid state: {state}") | ||
|
|
||
| branch_data = self.jsonrpc_call( | ||
| session_id=session_id, | ||
| model="res.company", | ||
| method="create", | ||
| args= [ | ||
| { | ||
| "name": branch_name, | ||
| "parent_id": 1, | ||
| "currency_id": 1, | ||
| "country_id": 104, | ||
| "state_id": state_id, | ||
| "street": street, | ||
| "city": city, | ||
| "active": True | ||
| } | ||
| ], | ||
| kwargs= {} | ||
| ) | ||
| if not branch_data: | ||
| raise HTTPException(status_code=404, detail="Error in creating branch") | ||
|
|
||
| POSProcessor.save_branch_details(bot, branch_name, branch_data, user) | ||
| return {"branch_id": branch_data, "status": "created"} | ||
|
|
||
| def accept_pos_order(self, session_id: str, order_id: int) -> Dict[str, Any]: | ||
| """ | ||
| Accept a POS order: tries to create payment and invoice it. | ||
|
|
||
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.
Handle case when no POS config matches the provided
company_id.If no config matches the
company_id,config_idremainsNone, which will cause downstream errors when creating the POS session. Add validation after the loop.🐛 Proposed fix
config_id = None for config in pos_configs: comp_id = config["company_id"][0] if config.get("company_id") else False if company_id == comp_id: config_id = config["id"] break + + if config_id is None: + raise AppException(f"No POS Config found for company_id {company_id}")📝 Committable suggestion
🤖 Prompt for AI Agents