diff --git a/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/PurchasePackingList_buildInvoice.xml b/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/PurchasePackingList_buildInvoice.xml
index f4e74f647e1a77b8d3cbcdc18bc1f8129bb21c24..a11a5c12b6ddac31a3c29664b101aabef0a39e37 100644
--- a/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/PurchasePackingList_buildInvoice.xml
+++ b/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/PurchasePackingList_buildInvoice.xml
@@ -67,7 +67,13 @@ if packing_list.getPortalType() == \'Purchase Packing List\':\n
   # WARNING: this tag is also used in InvoiceTransaction_postGeneration script\n
   tax_tag = \'build_invoice_tax_%s\' % packing_list.getRelativeUrl()\n
 \n
-  invoice_line_builder = getattr(delivery_tool, \'purchase_invoice_builder\', None)\n
+  invoice_builder_name = \'purchase_invoice_builder\'\n
+  invoice_tax_builder_name = \'purchase_invoice_tax_builder\'\n
+  if \'Purchase Invoice Module\' in context.getPortalModuleTypeList():\n
+    invoice_builder_name = \'advanced_purchase_invoice_builder\'\n
+    invoice_tax_builder_name = \'advanced_purchase_invoice_tax_builder\'\n
+\n
+  invoice_line_builder = getattr(delivery_tool,  invoice_builder_name , None)\n
   if invoice_line_builder is not None:\n
     invoice_line_builder.activate(\n
           activity=\'SQLQueue\',\n
@@ -80,7 +86,7 @@ if packing_list.getPortalType() == \'Purchase Packing List\':\n
   else:\n
     log(\'no purchase_invoice_builder found\')\n
 \n
-  invoice_tax_builder = getattr(delivery_tool, \'purchase_invoice_tax_builder\', None)\n
+  invoice_tax_builder = getattr(delivery_tool, invoice_tax_builder_name, None)\n
   if invoice_tax_builder is not None:\n
     invoice_tax_builder.activate(\n
           activity=\'SQLQueue\',\n
@@ -140,6 +146,9 @@ if packing_list.getPortalType() == \'Purchase Packing List\':\n
                             <string>None</string>
                             <string>tag</string>
                             <string>tax_tag</string>
+                            <string>invoice_builder_name</string>
+                            <string>invoice_tax_builder_name</string>
+                            <string>context</string>
                             <string>getattr</string>
                             <string>invoice_line_builder</string>
                             <string>dict</string>
diff --git a/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/SalePackingList_buildInvoice.xml b/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/SalePackingList_buildInvoice.xml
index 13c9f619c577cee96ea6b1ddd1054da8da3d8292..45e434259a874138bbb0a19c21335f746806cbe7 100644
--- a/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/SalePackingList_buildInvoice.xml
+++ b/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/packing_list_workflow/scripts/SalePackingList_buildInvoice.xml
@@ -67,7 +67,13 @@ if packing_list.getPortalType() == \'Sale Packing List\':\n
   # WARNING: this tag is also used in InvoiceTransaction_postGeneration script\n
   tax_tag = \'build_invoice_tax_%s\' % packing_list.getRelativeUrl()\n
 \n
-  invoice_line_builder = getattr(delivery_tool, \'sale_invoice_builder\', None)\n
+  invoice_builder_name = \'sale_invoice_builder\'\n
+  invoice_tax_builder_name = \'sale_invoice_tax_builder\'\n
+  if \'Sale Invoice Module\' in context.getPortalModuleTypeList():\n
+    invoice_builder_name = \'advanced_sale_invoice_builder\'\n
+    invoice_tax_builder_name = \'advanced_sale_invoice_tax_builder\'\n
+ \n
+  invoice_line_builder = getattr(delivery_tool, invoice_builder_name, None)\n
   if invoice_line_builder is not None:\n
     invoice_line_builder.activate(\n
           activity=\'SQLQueue\',\n
@@ -80,7 +86,7 @@ if packing_list.getPortalType() == \'Sale Packing List\':\n
   else:\n
     log(\'no sale_invoice_builder found\')\n
 \n
-  invoice_tax_builder = getattr(delivery_tool, \'sale_invoice_tax_builder\', None)\n
+  invoice_tax_builder = getattr(delivery_tool, invoice_tax_builder_name, None)\n
   if invoice_tax_builder is not None:\n
     invoice_tax_builder.activate(\n
           activity=\'SQLQueue\',\n
@@ -140,6 +146,9 @@ if packing_list.getPortalType() == \'Sale Packing List\':\n
                             <string>None</string>
                             <string>tag</string>
                             <string>tax_tag</string>
+                            <string>invoice_builder_name</string>
+                            <string>invoice_tax_builder_name</string>
+                            <string>context</string>
                             <string>getattr</string>
                             <string>invoice_line_builder</string>
                             <string>dict</string>
diff --git a/bt5/erp5_trade/bt/change_log b/bt5/erp5_trade/bt/change_log
index c3f2405a7011c7e70ca77e498ec74a919c6b3ded..18d7d08c2d5e0a5c5b07dcd143da0feeaf384b9d 100644
--- a/bt5/erp5_trade/bt/change_log
+++ b/bt5/erp5_trade/bt/change_log
@@ -1,3 +1,6 @@
+2009-06-19 tatuya
+* Fix workflow scripts to enable to create  Sale Invoices and Purchase Invoices when using erp5_advanced_invoicing
+
 2009-05-19 yusei
 * Fix some proxy fields. count_method should not be inherited from template field and proxy_listbox_ids had to be copied to new proxified fields but it was not copied.
 
diff --git a/bt5/erp5_trade/bt/revision b/bt5/erp5_trade/bt/revision
index 0552576c870884d40c4101e045c07fcf945e552e..38bfa57c0c565322877ca643e61ea7e8e2a64553 100644
--- a/bt5/erp5_trade/bt/revision
+++ b/bt5/erp5_trade/bt/revision
@@ -1 +1 @@
-669
\ No newline at end of file
+681
\ No newline at end of file