Author: hansbak Date: Wed Jun 19 05:53:20 2013 New Revision: 1494464 URL: http://svn.apache.org/r1494464 Log: when a sales order is completed and no payment is created, this will create a payment in the 'not paid' status which can be disabled in the accounting properties file, when it is a order in foreign currency it will use the same exchange rate as when will be used for the related invoice
Modified: ofbiz/trunk/applications/accounting/config/AccountingConfig.properties ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml ofbiz/trunk/applications/accounting/servicedef/services_payment.xml ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml ofbiz/trunk/applications/order/servicedef/secas.xml Modified: ofbiz/trunk/applications/accounting/config/AccountingConfig.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingConfig.properties?rev=1494464&r1=1494463&r2=1494464&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/config/AccountingConfig.properties (original) +++ ofbiz/trunk/applications/accounting/config/AccountingConfig.properties Wed Jun 19 05:53:20 2013 @@ -37,5 +37,8 @@ accounting.payment.application.autocreat # create a 'not-paid' payment record if the purchase order is approved accounting.payment.purchaseorder.autocreate=Y +# create a 'not-paid' payment record if the sales order is completed and no payment exist yet. +accounting.payment.salesorder.autocreate=Y + # create invoice per shipment = Y Invoice per order = N create.invoice.per.shipment=Y Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml?rev=1494464&r1=1494463&r2=1494464&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml Wed Jun 19 05:53:20 2013 @@ -870,15 +870,38 @@ under the License. </iterate> </simple-method> - <simple-method method-name="createPaymentFromOrder" short-description="Service auto create Payment from Order"> - - <property-to-field resource="AccountingConfig" property="accounting.payment.purchaseorder.autocreate" field="autoCreate" default="Y"/> - <if-compare operator="not-equals" value="Y" field="autoCreate"> - <log level="info" message="payment not created from approved order because config is not set to Y (AccountingConfig.properties)"/> - <return/> - </if-compare> - + <simple-method method-name="createPaymentFromOrder" short-description="Service auto create Payment from Order when payment does exist yet and not diabled by accountingconfig"> + <entity-one value-field="orderHeader" entity-name="OrderHeader"/> + + <if-compare operator="equals" value="PURCHASE_ORDER" field="orderHeader.orderTypeId"> + <property-to-field resource="AccountingConfig" property="accounting.payment.purchaseorder.autocreate" field="purchaseAutoCreate" default="Y"/> + <if-compare operator="not-equals" value="Y" field="purchaseAutoCreate"> + <log level="info" message="payment not created from approved order because config (accounting.payment.purchaseorder.autocreate) is not set to Y (AccountingConfig.properties)"/> + <return/> + </if-compare> + </if-compare> + + <if-compare operator="equals" value="SALES_ORDER" field="orderHeader.orderTypeId"> + <property-to-field resource="AccountingConfig" property="accounting.payment.salesorder.autocreate" field="salesAutoCreate" default="Y"/> + <if-compare operator="not-equals" value="Y" field="salesAutoCreate"> + <log level="info" message="payment not created from approved order because config (accounting.payment.salesorder.autocreate) is not set to Y (AccountingConfig.properties)"/> + <return/> + </if-compare> + </if-compare> + <!-- check if orderPaymentPreference with payment already exist, if yes do not re-create --> + <entity-condition entity-name="OrderPaymentPrefAndPayment" list="orderPaymentPrefAndPayments"> + <condition-list combine="and"> + <condition-expr field-name="orderId" operator="equals" from-field="orderHeader.orderId"/> + <condition-expr field-name="statusId" operator="not-equals" value="PAYMENT_CANCELLED"/> + </condition-list> + </entity-condition> + + <if-not-empty field="orderPaymentPrefAndPayments"> + <log level="info" message="Payment not created for order ${orderHeader.orderId}, at least a single payment already exists"/> + <return/> + </if-not-empty> + <entity-and list="orderRoleToList" entity-name="OrderRole"> <field-map field-name="orderId" from-field="orderHeader.orderId"/> <field-map field-name="roleTypeId" value="BILL_FROM_VENDOR"/> @@ -927,7 +950,7 @@ under the License. <now-timestamp field="parameters.effectiveDate"/> </if-empty> - <!-- check currency and when required convert--> + <!-- check currency and when required use invoice currency rate or convert when invoice not available --> <set field="partyAccountingPreferencesMap.organizationPartyId" from-field="organizationPartyId"/> <call-service service-name="getPartyAccountingPreferences" in-map-name="partyAccountingPreferencesMap"> <result-to-field result-name="partyAccountingPreference" field="partyAcctgPreference"/> @@ -936,6 +959,16 @@ under the License. <set field="parameters.currencyUomId" from-field="orderHeader.currencyUom"/> <set field="parameters.amount" from-field="orderHeader.grandTotal"/> <else> + <!-- get conversion rate from related invoice when exists --> + <entity-and list="invoices" entity-name="OrderItemBillingAndInvoiceAndItem"> + <field-map field-name="orderId" from-field="orderId"/> + </entity-and> + <if-not-empty field="invoices"> + <entity-one entity-name="Invoice" value-field="invoice"> + <field-map field-name="invoiceId" from-field="invoices[0].invoiceId"/> + </entity-one> + <set field="convertUomInMap.asOfDate" from-field="invoice.invoiceDate"/> + </if-not-empty> <set field="convertUomInMap.originalValue" from-field="orderHeader.grandTotal"/> <set field="convertUomInMap.uomId" from-field="orderHeader.currencyUom"/> <set field="convertUomInMap.uomIdTo" from-field="partyAcctgPreference.baseCurrencyUomId"/> @@ -945,7 +978,6 @@ under the License. <set field="parameters.actualCurrencyAmount" from-field="orderHeader.grandTotal"/> <set field="parameters.actualCurrencyUomId" from-field="orderHeader.currencyUom"/> <set field="parameters.currencyUomId" from-field="partyAcctgPreference.baseCurrencyUomId"/> - <set field="parameters.actualCurrencyUomId" from-field="orderHeader.currencyUom"/> </else> </if-compare-field> @@ -959,6 +991,7 @@ under the License. </call-service> <set field="parameters.orderId" from-field="orderHeader.orderId"/> <set field="parameters.maxAmount" from-field="orderHeader.grandTotal"/> + <set-service-fields service-name="createOrderPaymentPreference" to-map="newOrderPaymentPreference" map="parameters"/> <call-service service-name="createOrderPaymentPreference" in-map-name="newOrderPaymentPreference"> <result-to-field result-name="orderPaymentPreferenceId" field="parameters.paymentPreferenceId"/> Modified: ofbiz/trunk/applications/accounting/servicedef/services_payment.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_payment.xml?rev=1494464&r1=1494463&r2=1494464&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/services_payment.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/services_payment.xml Wed Jun 19 05:53:20 2013 @@ -236,9 +236,12 @@ under the License. <service name="createPaymentFromOrder" engine="simple" location="component://accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml" invoke="createPaymentFromOrder" auth="true"> - <description>create Payment from Order</description> + <description>Create Payment from Order when payment does exist yet and not disabled by accountingconfig</description> <attribute name="orderId" type="String" mode="IN" optional="false"/> <attribute name="paymentId" type="String" mode="OUT" optional="true"/> + <attribute name="paymentMethodId" type="String" mode="IN" optional="true"/> + <attribute name="paymentRefNum" type="String" mode="IN" optional="true"/> + <attribute name="comments" type="String" mode="IN" optional="true"/> </service> <service name="createMatchingPaymentApplication" engine="simple" Modified: ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml?rev=1494464&r1=1494463&r2=1494464&view=diff ============================================================================== --- ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml (original) +++ ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml Wed Jun 19 05:53:20 2013 @@ -138,6 +138,25 @@ under the License. <key-map field-name="orderPaymentPreferenceId"/> </relation> </view-entity> + <view-entity entity-name="OrderPaymentPrefAndPayment" + package-name="org.ofbiz.order.order" + never-cache="true" + title="Payment Preference and Payment View Entity"> + <member-entity entity-alias="PF" entity-name="OrderPaymentPreference"/> + <member-entity entity-alias="PMT" entity-name="Payment"/> + <alias entity-alias="PF" name="orderPaymentPreferenceId"/> + <alias entity-alias="PF" name="orderId"/> + <alias entity-alias="PF" name="statusId"/> + <alias entity-alias="PMT" name="paymentId"/> + <alias entity-alias="PMT" name="paymentTypeId"/> + <alias entity-alias="PMT" name="amount"/> + <view-link entity-alias="PF" rel-entity-alias="PMT"> + <key-map field-name="orderPaymentPreferenceId" rel-field-name="paymentPreferenceId"/> + </view-link> + <relation type="one-nofk" rel-entity-name="OrderHeader"> + <key-map field-name="orderId"/> + </relation> + </view-entity> <view-entity entity-name="OrderHeaderAndRoleSummary" package-name="org.ofbiz.order.order" never-cache="true" Modified: ofbiz/trunk/applications/order/servicedef/secas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=1494464&r1=1494463&r2=1494464&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/order/servicedef/secas.xml Wed Jun 19 05:53:20 2013 @@ -96,6 +96,8 @@ under the License. <action service="sendOrderCompleteNotification" mode="async" persist="true"/> <action service="createReturnItemForRental" mode="sync"/> </eca> + + <!-- create payment from purchase order when approved (can be disabled by accountingConfig)--> <eca service="changeOrderStatus" event="commit" run-on-error="false"> <condition field-name="orderTypeId" operator="equals" value="PURCHASE_ORDER"/> <condition field-name="statusId" operator="equals" value="ORDER_APPROVED"/> @@ -103,6 +105,14 @@ under the License. <action service="createPaymentFromOrder" mode="sync" persist="true"/> </eca> + <!-- create payment from sales order when completed and not created yet (can be disabled by accountingConfig) --> + <eca service="changeOrderStatus" event="commit" run-on-error="false"> + <condition field-name="orderTypeId" operator="equals" value="SALES_ORDER"/> + <condition field-name="statusId" operator="equals" value="ORDER_COMPLETED"/> + <condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/> + <action service="createPaymentFromOrder" mode="sync" persist="true"/> + </eca> + <!-- DISABLED FOR NOW <eca service="changeOrderStatus" event="commit" run-on-error="false"> <condition field-name="statusId" operator="equals" value="ORDER_PROCESSING"/>