I am a beginner with Odoo ( V14.0 ) and its API.
I managed to perform some actions with trial and error and here, I try to create an invoice based on what I saw passing as data in the Chrome console.
I have advanced step by step and now I don't get any error but I still don't see any invoice appearing.
Can you help me or give me a procedure? Thanks in advance.
function new_invoice() {
$doc = [
"date" => "2021-08-18",
"asset_id" => false,
"show_name_warning" => false,
"posted_before" => false,
"payment_state" => "not_paid",
"name" => "/NEW/PLUS/".date("ymdhis"),
"partner_id" => 20346,
"partner_shipping_id" => 20346,
"ref" => false,
"payment_reference" => "UUDYYD" . date("ymdhis"),
"partner_bank_id" => false,
"invoice_vendor_bill_id" => false,
"purchase_id" => false,
"purchase_vendor_bill_id" => false,
"invoice_date" => "2021-08-18",
"invoice_date_due" => "2021-09-17",
"invoice_payment_term_id" => 4,
"journal_id" => 1,
"currency_id" => 1,
"edi_document_ids" => [],
"invoice_line_ids" => [
[
0,
"virtual_2375",
[
"sequence" => 10,
"product_id" => 2962,
"name" => "[106 -CP] Wit 5 ml doseerpipet",
"account_id" => 374,
"analytic_account_id" => false,
"analytic_tag_ids" => [
[
6,
false,
[]
]
],
"quantity" => 1,
"product_uom_id" => 1,
"price_unit" => 5,
"discount" => 0,
"tax_ids" => [
[
6,
false,
[
1
]
]
],
"partner_id" => 20346,
"amount_currency" => -5,
"currency_id" => 1,
"debit" => 0,
"credit" => 5,
"date_maturity" => false,
"tax_tag_ids" => [
[
6,
false,
[
11
]
]
],
"purchase_line_id" => false,
"recompute_tax_line" => false,
"predict_from_name" => false,
"display_type" => false,
"is_rounding_line" => false,
"exclude_from_invoice_tab" => false,
"parent_state" => "draft"
]
]
],
"line_ids" => [
[
0,
"virtual_2379",
[
"account_id" => 178,
"sequence" => 10,
"name" => "UUDYYD",
"quantity" => 1,
"price_unit" => -6.05,
"discount" => 0,
"debit" => 6.05,
"credit" => 0,
"amount_currency" => 6.05,
"date_maturity" => "2021-09-17",
"currency_id" => 1,
"partner_id" => 20346,
"product_uom_id" => false,
"product_id" => false,
"tax_ids" => [
[
6,
false,
[]
]
],
"tax_base_amount" => 0,
"tax_exigible" => true,
"tax_repartition_line_id" => false,
"tax_tag_ids" => [
[
6,
false,
[]
]
],
"analytic_account_id" => false,
"analytic_tag_ids" => [
[
6,
false,
[]
]
],
"recompute_tax_line" => false,
"display_type" => false,
"is_rounding_line" => false,
"exclude_from_invoice_tab" => true,
"purchase_line_id" => false,
"predict_from_name" => false
]
],
[
0,
"virtual_2375",
[
"account_id" => 374,
"sequence" => 10,
"name" => "[106 -CP] Wit 5 ml doseerpipet",
"quantity" => 1,
"price_unit" => 5,
"discount" => 0,
"debit" => 0,
"credit" => 5,
"amount_currency" => -5,
"date_maturity" => false,
"currency_id" => 1,
"partner_id" => 20346,
"product_uom_id" => 1,
"product_id" => 2962,
"tax_ids" => [
[
6,
false,
[
1
]
]
],
"tax_base_amount" => 0,
"tax_exigible" => true,
"tax_repartition_line_id" => false,
"tax_tag_ids" => [
[
6,
false,
[
11
]
]
],
"analytic_account_id" => false,
"analytic_tag_ids" => [
[
6,
false,
[]
]
],
"recompute_tax_line" => false,
"display_type" => false,
"is_rounding_line" => false,
"exclude_from_invoice_tab" => false,
"purchase_line_id" => false,
"predict_from_name" => false
]
],
[
0,
"virtual_2385",
[
"account_id" => 221,
"sequence" => 10,
"name" => "21%",
"quantity" => 1,
"price_unit" => 1.05,
"discount" => 0,
"debit" => 0,
"credit" => 1.05,
"amount_currency" => -1.05,
"date_maturity" => false,
"currency_id" => 1,
"partner_id" => 20346,
"product_uom_id" => false,
"product_id" => false,
"tax_ids" => [
[
6,
false,
[]
]
],
"tax_base_amount" => 5,
"tax_exigible" => true,
"tax_repartition_line_id" => 2,
"tax_tag_ids" => [
[
6,
false,
[
47
]
]
],
"analytic_account_id" => false,
"analytic_tag_ids" => [
[
6,
false,
[]
]
],
"recompute_tax_line" => false,
"display_type" => false,
"is_rounding_line" => false,
"exclude_from_invoice_tab" => true,
"purchase_line_id" => false,
"predict_from_name" => false
]
]
],
"invoice_user_id" => 2,
"team_id" => 5,
"invoice_origin" => false,
"qr_code_method" => false,
"invoice_incoterm_id" => false,
"fiscal_position_id" => 2,
"invoice_cash_rounding_id" => false,
"invoice_source_email" => false,
"auto_post" => false,
"to_check" => false,
"campaign_id" => false,
"medium_id" => false,
"source_id" => false,
"message_follower_ids" => [],
"activity_ids" => [],
"message_main_attachment_id" => false,
"message_ids" => []
];
$invoice = $this->models->execute_kw( $this->db, $this->uid, $this->password, 'account.move', 'create', [$doc], );
echo $invoice; /* ---> It returns a number */
$action = $this->models->execute_kw( $this->db, $this->uid, $this->password, 'account.move', 'action_post', [$invoice] );
print_r($action); /* It does not return anything */
}
what you receive when you print/echo the invoice variable ? if you get an id, you can check that id in the db for the created record
With the "Create" method, I get an ID, like "46", but the following command returns nothing
I don't know how to access the contents of the DB. I am Odoo.sh