Bỏ qua để đến nội dung

Sinh hoá đơn Lease recurring (Cron)

Cron job chạy 06:00 hàng sáng — scan tất cả HĐ active có billing_item đến hạn phát sinh → tạo Invoice draft cho FC review.

  • Chỉ HĐ state = active hoặc renewed được scan
  • Chỉ billing_item cadence recurring (monthly, quarterly, yearly) mới sinh
  • Cadence one-time → sinh khi milestone linked → done
  • HĐ state = draft / pending / closed / terminated → skip

Mỗi Invoice có:

FieldValue
Partnercontract.customer_id
Invoice dateNgày cron chạy
Due dateNgày phát sinh + payment_term.day (vd Net 30)
JournalCustomer Invoices (hoặc Lease nếu custom)
Currencycontract.currency_id
Lines1 line per billing_item đến hạn
Line description"[Contract#] Kỳ tháng X/YYYY — <billing_item.name>"
Line amountAmount theo cadence
Line taxbilling_item.tax_id (default VAT 10%)
StateDraft (nếu auto-post = OFF) hoặc Posted (nếu ON)
CadenceKhi nào sinh
MonthlyNgày 1 hàng tháng (hoặc ngày cụ thể theo billing_start_day)
QuarterlyNgày 1 của tháng 1/4/7/10
YearlyNgày 1/1 hoặc anniversary_date
One-timeKhi milestone linked → done

Cấu hình → Company → tab Cấu hình → “Auto-post Lease Invoices”:

Cron CHỈ tạo draft. FC phải:

  1. Mở Hoá đơn → Bản nháp
  2. Review từng draft
  3. Confirm (= Post)
  4. (Optional) Send email KH

Khuyến nghị 3 tháng đầu để verify logic đúng.

Cron mặc định 06:00. Để test ngay (Admin):

  1. Bật dev mode
  2. Cấu hình → Technical → Automation → Scheduled Actions
  3. Tìm Parkone: Sinh hoá đơn lease định kỳ
  4. Click “Run Manually”
  5. Xem log:
    • Tạo bao nhiêu Invoice
    • Contract nào skip (không có billing_item đến hạn)
    • Error nếu có
  1. Hoá đơn → Bản nháp — xem list draft
  2. Filter by “Ngày hoá đơn = today”
  3. Verify:
    • Đúng KH
    • Đúng số tiền
    • Đúng tax
    • Description rõ ràng
  4. Nếu OK → tick chọn tất cả → menu Action → Confirm (post batch)

Xem chi tiết Milestone editor → Invoice trigger.

Tóm tắt:

  • Set milestone → done
  • Cron 30 phút sau tạo Invoice draft
  • Amount = amount_pct × line.price_subtotal

Đại có thể đổi thời gian chạy cron:

  1. Dev mode → Technical → Scheduled Actions
  2. Parkone: Sinh hoá đơn lease định kỳ
  3. Đổi:
    • Nextcall: lần chạy tiếp theo (auto reschedule)
    • Interval Number + Type: 1 Days = mỗi ngày
    • User: user cron chạy (mặc định admin — không đổi)
  4. Save

Khuyến nghị giữ default 06:00 daily.

Nếu KH có 3 HĐ với 3 KCN khác nhau, cron sẽ sinh 3 Invoices riêng (không merge).

Nếu KH muốn merge → tạo account.move group manual (Odoo hỗ trợ combine invoices).

  • HĐ terminated ngày 15/8 → cron ngày 1/9 skip HĐ này
  • Invoice tháng 8 đã sinh (từ 1/8) → FC prorate manual (chỉnh amount = amount × 15/31)

Cron dùng billing_item.get_amount_at_date(date) — auto compute escalation based on year vs HĐ start:

Năm 1-5: 50,000 VND/m²/year
Năm 6-10: 52,500
...

Không cần Đại làm gì.

  • Nếu KH không active partner (active=False) → cron skip
  • Nếu KH bị block (x_supplier_status=blocked) → cron log warning

Menu Technical → Scheduled Actions → xem Last executedLog.

Common errors:

  • account_move: partner_id required → HĐ missing customer_id, sửa HĐ
  • no journal for currency → thiếu journal cho currency, thêm trong Cấu hình → Journals
  • period locked → fiscal period đã lock, sửa ngày Invoice hoặc unlock
  • HĐ draft: xoá trực tiếp (icon 🗑️)
  • HĐ posted nhưng chưa payment: menu Action → Reset to draft → sửa/xoá
  • HĐ posted + có payment: KHÔNG xoá được. Tạo Credit Note để offset.

Cron chạy 2 lần trong ngày (test) → sinh trùng?

Phần tiêu đề “Cron chạy 2 lần trong ngày (test) → sinh trùng?”

Cron có anti-duplicate: check billing_item.last_invoiced_month = current month → skip.

Nếu Đại reset field này (Advanced) → chạy lại sẽ sinh trùng. Chỉ dùng khi cần regenerate.

Chia sẻ: