pos_export_bc/README.md

52 lines
3.9 KiB
Markdown

# POS Export BC Format
This is a custom Odoo 19 module designed specifically to export Point of Sale (POS) orders and sales data into a highly structured Excel layout required for "MIE MAPAN INVOICES". This module focuses on ensuring accurate accounting aggregations, proper chronological date handling, and layout consistency for reporting purposes.
## Key Features
1. **Custom Row-Aggregated Excel Generation**
- Traditional exports list line items uniformly. This module groups the sales data by order. Order-level aggregates (such as *Total Charge*, *Subtotal*, *Tax*, *Paid Amount*, *Return*) are printed exclusively on the first row of each order's line items.
- Subsequent line items for the same order only show item-specific details like *Product Name*, *SKU*, *Quantity*, and *Unit Price*, keeping the spreadsheet clean and highly readable.
2. **Automated "Invoice" and "Refund" Splitting**
- The module automatically detects standard positive orders and negative return orders.
- It separates them dynamically into two distinct sheets within the same workbook: **"Invoice"** (for orders with a total >= 0) and **"Refund"** (for orders with a total < 0).
3. **Custom "Dinein" vs "Takeaway" Logic & Naming Fallbacks**
- Automatically determines if an order is for Dine-in or Takeaway based on whether a POS table is assigned.
- If a table is assigned, the system explicitly records it as `"dinein"`.
- If no table is assigned, the system automatically records it as `"takeaway"`.
- The **Table/Customer** column intelligently uses fallbacks: it prioritizes the exact table number (stripping the floor name), falls back to the floating order name (for takeaways), and finally falls back to the customer's name.
4. **Integration with Odoo Studio Custom Fields**
- Specifically configured to pull SKU values from a custom Odoo Studio product field (`x_studio_bc_item_id`), seamlessly bridging standard Point of Sale code with codeless customizations.
5. **Precise Formatting and Value Handling**
- Outputs datetime data (such as "Date" and "Paid At") as strict text strings (format: `DD-MM-YYYY HH:MM:SS`) to bypass Excel's aggressive, and often erroneous, timezone/date auto-formatting.
- Correctly calculates the amount paid by only summing positive payment tenders and using standard POS change allocations for exact accounting matches.
- Computes an aggregate order-level **Discount** by intelligently scanning all lines in the order for negative prices and summing their pre-tax subtotals.
- Dynamically formats the Excel filename using the uppercase Company Registry, shortened dates (YYMMDD), and hard length-capping (max 40 characters) to meet tight system naming requirements (e.g. `POS_MMSBYSABRJ_260607_to_260608.xlsx`).
## Requirements
The module performs in-memory Excel generation rather than writing physical files, requiring the `xlsxwriter` library.
Install it via your environment's package manager:
```sh
pip install xlsxwriter
```
## How to Use
1. **Install Module:** Navigate to the Odoo **Apps** menu and install `POS Export BC Format`.
2. **Open the Tool:** Go to the backend **Point of Sale** application. Click on **Reporting** in the top menu and select **Export BC Format**.
3. **Select Period:** A wizard window will prompt you for a **Start Date** and **End Date**.
4. **Generate:** Click the **Export to BC Format** button.
5. **Download:** A dynamically generated `.xlsx` file will automatically download to your browser.
## Technical Structure
- **Models / Wizards**: Leverages an Odoo `TransientModel` (`pos.export.bc.wizard`) to prompt users for date ranges.
- **Generation Logic**: The python script aggregates `pos.order` models matching the domain, then systematically writes rows into an `io.BytesIO` stream using the `xlsxwriter.Workbook`.
- **Delivery**: The memory stream is temporarily saved to `ir.attachment` and served via a standard Odoo HTTP controller url act window (`/web/content/<id>?download=true`).