Add submitted state to payment
This allow to process receivable payment without approval. issue11190 review370731002
This commit is contained in:
+25
-8
@@ -202,23 +202,23 @@ class Payment(CheckoutMixin, BraintreeCustomerMethodMixin, metaclass=PoolMeta):
|
||||
cls.amount.states['readonly'] &= ~Eval('braintree_settlement_needed')
|
||||
|
||||
cls.braintree_customer.states['readonly'] = (
|
||||
~Eval('state').in_(['draft', 'approved'])
|
||||
~Eval('state').in_(['draft', 'submitted', 'approved'])
|
||||
| Eval('braintree_nonce'))
|
||||
|
||||
cls.braintree_customer_method.states['invisible'] |= (
|
||||
Eval('braintree_nonce'))
|
||||
cls.braintree_customer_method.states['readonly'] = (
|
||||
~Eval('state').in_(['draft', 'approved']))
|
||||
~Eval('state').in_(['draft', 'submitted', 'approved']))
|
||||
|
||||
cls.braintree_customer_method_selection.states['invisible'] |= (
|
||||
Eval('braintree_nonce'))
|
||||
cls.braintree_customer_method_selection.states['readonly'] = (
|
||||
~Eval('state').in_(['draft', 'approved']))
|
||||
~Eval('state').in_(['draft', 'submitted', 'approved']))
|
||||
|
||||
cls._buttons.update({
|
||||
'braintree_checkout': {
|
||||
'invisible': (~Eval('state', 'draft').in_(
|
||||
['approved', 'processing'])
|
||||
['submitted', 'approved', 'processing'])
|
||||
| (Eval('process_method') != 'braintree')
|
||||
| Eval('braintree_nonce')
|
||||
| Eval('braintree_customer_method')),
|
||||
@@ -529,12 +529,16 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView):
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
})
|
||||
submitted_by = employee_field(
|
||||
"Submitted by",
|
||||
states=['submitted', 'approved', 'processing', 'succeeded', 'failed'])
|
||||
approved_by = employee_field(
|
||||
"Approved by",
|
||||
states=['approved', 'processing', 'succeeded', 'failed'])
|
||||
|
||||
state = fields.Selection([
|
||||
('draft', "Draft"),
|
||||
('submitted', "Submitted"),
|
||||
('approved', "Approved"),
|
||||
('processing', "Processing"),
|
||||
('succeeded', "Succeeded"),
|
||||
@@ -562,7 +566,8 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView):
|
||||
super().__setup__()
|
||||
cls.__access__.add('payment')
|
||||
cls._transitions |= set((
|
||||
('draft', 'approved'),
|
||||
('draft', 'submitted'),
|
||||
('submitted', 'approved'),
|
||||
('approved', 'processing'),
|
||||
('processing', 'succeeded'),
|
||||
('processing', 'failed'),
|
||||
@@ -570,15 +575,20 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView):
|
||||
))
|
||||
cls._buttons.update({
|
||||
'draft': {
|
||||
'invisible': Eval('state') != 'approved',
|
||||
'invisible': ~Eval('state').in_(['approved', 'submitted']),
|
||||
'icon': 'tryton-back',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'approve': {
|
||||
'submit': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
'icon': 'tryton-forward',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'approve': {
|
||||
'invisible': Eval('state') != 'submitted',
|
||||
'icon': 'tryton-forward',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@@ -608,10 +618,17 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView):
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('draft')
|
||||
@reset_employee('approved_by')
|
||||
@reset_employee('submitted_by', 'approved_by')
|
||||
def draft(cls, refunds):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('submitted')
|
||||
@set_employee('submitted_by')
|
||||
def submit(cls, refunds):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('approved')
|
||||
|
||||
+23
-6
@@ -163,29 +163,36 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="count" eval="True"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_approved">
|
||||
<field name="name">Approved</field>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_to_approve">
|
||||
<field name="name">To Approve</field>
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="domain" eval="[('state', '=', 'submitted')]" pyson="1"/>
|
||||
<field name="count" eval="True"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_to_process">
|
||||
<field name="name">To Process</field>
|
||||
<field name="sequence" eval="30"/>
|
||||
<field name="domain" eval="[('state', '=', 'approved')]" pyson="1"/>
|
||||
<field name="count" eval="True"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_processing">
|
||||
<field name="name">Processing</field>
|
||||
<field name="sequence" eval="30"/>
|
||||
<field name="sequence" eval="40"/>
|
||||
<field name="domain" eval="[('state', '=', 'processing')]" pyson="1"/>
|
||||
<field name="count" eval="True"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_suceeded">
|
||||
<field name="name">Succeeded</field>
|
||||
<field name="sequence" eval="40"/>
|
||||
<field name="sequence" eval="50"/>
|
||||
<field name="domain" eval="[('state', '=', 'succeeded')]" pyson="1"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.domain" id="act_refund_form_domain_failed">
|
||||
<field name="name">Failed</field>
|
||||
<field name="sequence" eval="50"/>
|
||||
<field name="sequence" eval="60"/>
|
||||
<field name="domain" eval="[('state', '=', 'failed')]" pyson="1"/>
|
||||
<field name="act_window" ref="act_refund_form"/>
|
||||
</record>
|
||||
@@ -198,7 +205,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
|
||||
<menuitem
|
||||
parent="account_payment.menu_payments"
|
||||
sequence="50"
|
||||
sequence="20"
|
||||
action="act_refund_form"
|
||||
id="menu_refund_form"/>
|
||||
|
||||
@@ -212,6 +219,16 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="group" ref="account_payment.group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="refund_submit_button">
|
||||
<field name="name">submit</field>
|
||||
<field name="string">Submit</field>
|
||||
<field name="model" search="[('model', '=', 'account.payment.braintree.refund')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group" id="refund_submit_button_group_payment">
|
||||
<field name="button" ref="refund_draft_button"/>
|
||||
<field name="group" ref="account_payment.group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="refund_approve_button">
|
||||
<field name="name">approve</field>
|
||||
<field name="string">Approve</field>
|
||||
|
||||
@@ -81,7 +81,7 @@ Create party::
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create approved payment::
|
||||
Create submitted payment::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> payment = Payment()
|
||||
@@ -90,9 +90,9 @@ Create approved payment::
|
||||
>>> payment.party = customer
|
||||
>>> # Use random amount to prevent gateway rejection for duplicate
|
||||
>>> payment.amount = amount = Decimal(random.randint(0, 1999))
|
||||
>>> payment.click('approve')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
'submitted'
|
||||
|
||||
Checkout the payment::
|
||||
|
||||
@@ -175,9 +175,9 @@ Make payment with customer::
|
||||
>>> _, method = Payment.get_braintree_customer_methods(payment.id, config.context)
|
||||
>>> method_token, _ = method
|
||||
>>> payment.braintree_customer_method = method_token
|
||||
>>> payment.click('approve')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
'submitted'
|
||||
>>> process_payment = Wizard('account.payment.process', [payment])
|
||||
>>> process_payment.execute('process')
|
||||
>>> payment.state
|
||||
@@ -212,9 +212,9 @@ Create payment to settle::
|
||||
>>> payment.braintree_customer = None
|
||||
>>> payment.braintree_settle_payment = False
|
||||
>>> payment.amount = amount = Decimal(random.randint(0, 1999))
|
||||
>>> payment.click('approve')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
'submitted'
|
||||
|
||||
>>> Payment.write([payment.id], {
|
||||
... 'braintree_nonce': Nonces.Transactable,
|
||||
@@ -252,6 +252,7 @@ Refund some amount::
|
||||
>>> refund = Refund()
|
||||
>>> refund.payment = payment
|
||||
>>> refund.amount = amount - 1
|
||||
>>> refund.click('submit')
|
||||
>>> refund.click('approve')
|
||||
>>> cron_refund, = Cron.find([
|
||||
... ('method', '=', 'account.payment.braintree.refund|braintree_refund'),
|
||||
@@ -287,6 +288,7 @@ Try to refund more::
|
||||
>>> refund = Refund()
|
||||
>>> refund.payment = payment
|
||||
>>> refund.amount = Decimal('10')
|
||||
>>> refund.click('submit')
|
||||
>>> refund.click('approve')
|
||||
>>> cron_refund.click('run_once')
|
||||
>>> refund.reload()
|
||||
|
||||
@@ -10,14 +10,16 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="braintree_error_message"/>
|
||||
<field name="braintree_error_message" colspan="3" yexpand="0" height="80"/>
|
||||
|
||||
<label name="submitted_by"/>
|
||||
<field name="submitted_by"/>
|
||||
<label name="approved_by"/>
|
||||
<field name="approved_by"/>
|
||||
<newline/>
|
||||
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
<group col="-1" colspan="2" id="buttons">
|
||||
<button name="draft"/>
|
||||
<button name="submit"/>
|
||||
<button name="approve"/>
|
||||
</group>
|
||||
</form>
|
||||
|
||||
@@ -5,4 +5,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="payment" expand="1"/>
|
||||
<field name="amount" expand="2"/>
|
||||
<field name="state"/>
|
||||
<button name="submit"/>
|
||||
<button name="approve"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user