PHP code example of jsadways / odoo-api
1. Go to this page and download the library: Download jsadways/odoo-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jsadways / odoo-api example snippets
use Jsadways\OdooApi\Facades\Odoo;
use Jsadways\OdooApi\Enums\OdooEndpoint;
use Jsadways\OdooApi\Dtos\Campaign\CampaignCreateDto;
use Jsadways\OdooApi\Dtos\Campaign\CampaignCueDto;
$result = Odoo::create(
OdooEndpoint::CAMPAIGN_CREATE,
new CampaignCreateDto(
organization: 1,
name: 'Apple Q126 宣傳_202511-12',
client_id: 53,
campaign_number: '2511000',
start_dt: '2025-10-28',
end_dt: '2026-11-19',
price: 100000,
tax: 5000,
total_price: 105000,
status: 1,
exchange_rate: 1,
cue: [
new CampaignCueDto(
cue_number: 315,
product_id: 69,
budget: 1999,
month: '202510',
income: 20000,
income_total: 16600,
income_discount: 2000,
income_rebate: 1400,
cost: 5000,
cost_total: 4850,
cost_discount: 50,
cost_rebate: 100,
profit_code: '03651',
cost_code: '075521',
),
],
)
);
// 建立
Odoo::create(OdooEndpoint::PARTNER_CREATE, new PartnerCreateDto(
type: 1, // 1=客戶, 2=供應商
name: 'AA廣告有限公司',
short_name: 'AA廣告',
en_name: 'AA INTEGRATION CO., LTD',
id_number: '80666612',
address: '台北市信義區...',
tel: '(02)22226666',
finance_email: null, // 可選
));
// 更新(多一個 id)
Odoo::update(OdooEndpoint::PARTNER_UPDATE, new PartnerUpdateDto(
id: 267,
type: 1,
name: 'AA廣告有限公司',
// ... 同 create 欄位
));
// 建立
Odoo::create(OdooEndpoint::PRODUCT_CREATE, new ProductCreateDto(
name: '媒體_Meta_服務費',
memo: '', // 可選
));
// 更新(支援多筆,data 為陣列)
Odoo::update(OdooEndpoint::PRODUCT_UPDATE, new ProductUpdateDto(
products: [
['id' => 158, 'name' => '媒體_Meta_服務費', 'memo' => ''],
['id' => 159, 'name' => '媒體_Meta_上刊費', 'memo' => ''],
]
));
Odoo::list(OdooEndpoint::INCOME_RECEIPT_LIST, new IncomeReceiptListDto(
filter: [
'keyword' => '關鍵字',
'campaign_id' => [53, 61],
'partner_id' => [871],
'receipt_number' => ['KK88909876'],
'receipt_date_start' => '20250101',
'receipt_date_end' => '20250301',
],
order_by: 'receipt_date', // 可選
order: 'DESC', // 可選
page: 1, // 可選
per_page: 30, // 可選
));
Odoo::create(OdooEndpoint::INCOME_RECEIPT_CREATE, new IncomeReceiptCreateDto(
campaign_id: 861,
receipt_type: 1, // 1=電子發票三聯, 2=二聯, 3=國外Invoice
dollar_type: 1, // 1=新台幣, 2=美金, 3=日幣
item_name: '廣告服務費',
price: 100000,
tax: 5000,
total_price: 105000,
cue: [
new IncomeReceiptCueDto(id: 871, finance_income: 80000, offseted_price: 20000, offset_price: 60000),
new IncomeReceiptCueDto(id: 872, finance_income: 60000, offseted_price: 20000, offset_price: 40000),
],
notification_email: [
new NotificationEmailDto(name: 'Abbie', email: '[email protected] '),
],
creator_name: 'Lex',
creator_email: '[email protected] ',
urgent: false, // 可選,預設 false
memo: '備註', // 可選
specify_dt: '20250101', // 可選
pickup_dt: '20250101', // 可選
));
Odoo::create(OdooEndpoint::INCOME_RECEIPT_DISCOUNT, new IncomeReceiptDiscountDto(
discount_reason: '退佣',
discount_dt: '20260113',
finance_dt: '20260113',
discount_type: 1, // 1=單純折讓, 2=現折, 3=退佣, 4=現折+退佣
discount_paper_type: 1, // 1=我方開立折讓單, 2=進項發票, 3=開立Credit note, 4=收到Debit note
price: 100000,
tax: 5000,
total_price: 105000,
receipt: [
new IncomeDiscountReceiptDto(
id: 573,
discount_price: 5000,
cue: [
new IncomeDiscountReceiptCueDto(id: 6288, discount_price: 3000),
new IncomeDiscountReceiptCueDto(id: 6289, discount_price: 2000),
],
),
],
creator_name: 'Lex',
creator_email: '[email protected] ',
credit_note: new IncomeCreditNoteDto(
dollar_type: 1,
item_name: '折讓',
credit_note_number: 'A784TYG887',
date: '20260113',
contact_name: '王小明',
contact_address: '台北市信義區...',
memo: '',
),
debit_note: new IncomeDebitNoteDto(dollar_type: 1, item_name: '折讓', debit_note_number: 'A784TYG887', file: ''),
cost_receipt: new IncomeCostReceiptDto(receipt_dt: '20260105', item_name: '退佣金', receipt_number: 'AA88765432', file: ''),
));
// 發票作廢
Odoo::create(OdooEndpoint::INCOME_RECEIPT_VOID, new IncomeReceiptVoidDto(
id: 751,
reason: '開錯金額',
creator_name: 'Lex',
creator_email: '[email protected] ',
reply_received: false, // 可選,預設 false
file: '', // 可選
reply_file: '', // 可選
));
// 收到客戶回覆後更新作廢資料
Odoo::update(OdooEndpoint::INCOME_RECEIPT_VOID_UPDATE, new IncomeReceiptVoidUpdateDto(
id: 751,
reply_received: true,
reply_file: '', // 可選
));
// 折讓作廢
Odoo::create(OdooEndpoint::INCOME_DISCOUNT_VOID, new IncomeDiscountVoidDto(
id: 27,
reason: '客戶不收',
creator_name: 'Lex',
creator_email: '[email protected] ',
file: '', // 可選
));
Odoo::create(OdooEndpoint::COST_RECEIPT_DISCOUNT, new CostReceiptDiscountDto(
discount_reason: '退佣',
discount_dt: '20260113',
finance_dt: '20260113',
discount_type: 1, // 1=單純折讓, 2=現折, 3=退佣, 4=現折+退佣
discount_paper_type: 1, // 1=我方開立折讓單, 2=對方開立, 3=開立銷項發票, 4=我方開立Debit note, 5=收到Credit note
price: 100000,
tax: 5000,
total_price: 105000,
receipt: [
new CostDiscountReceiptDto(
id: 6311,
discount_price: 5000,
cue: [
new CostDiscountReceiptCueDto(id: 316, discount_price: 3000),
new CostDiscountReceiptCueDto(id: 741, discount_price: 2000),
],
),
],
creator_name: 'Lex',
creator_email: '[email protected] ',
allowance: new CostAllowanceDto(file: ''),
credit_note: new CostCreditNoteDto(file: ''),
debit_note: new CostDebitNoteDto(
dollar_type: 1,
item_name: '折讓',
debit_note_number: 'A784TYG887',
date: '20260113',
contact_name: '王小明',
contact_address: '台北市信義區...',
memo: '',
),
income_receipt: new CostIncomeReceiptDto(receipt_dt: '20260105', item_name: '退佣金', receipt_number: 'AA88765432', file: ''),
));
$results = Odoo::retry();