feat: Se añade funcionalidad para cambiar metodo de pago
This commit is contained in:
69
sale.py
69
sale.py
@@ -37,10 +37,11 @@ class Sale(metaclass=PoolMeta):
|
||||
def __setup__(cls):
|
||||
super(Sale, cls).__setup__()
|
||||
cls._buttons.update({
|
||||
'wizard_sale_payment': {
|
||||
'invisible': Eval('state') == 'done',
|
||||
'readonly': Not(Bool(Eval('lines'))),
|
||||
'wizard_sale_payment': {
|
||||
'invisible': Eval('state') == 'done',
|
||||
'readonly': Not(Bool(Eval('lines'))),
|
||||
},
|
||||
'wizard_change_payment_method': {},
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
@@ -179,6 +180,11 @@ class Sale(metaclass=PoolMeta):
|
||||
def wizard_sale_payment(cls, sales):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button_action('sale_payment.wizard_sale_change_payment_method')
|
||||
def wizard_change_payment_method(cls, sales):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def copy(cls, sales, default=None):
|
||||
if default is None:
|
||||
@@ -187,6 +193,63 @@ class Sale(metaclass=PoolMeta):
|
||||
return super(Sale, cls).copy(sales, default)
|
||||
|
||||
|
||||
class ChangePaymentMethodForm(ModelView):
|
||||
'Change Payments Method form'
|
||||
__name__ = 'sale.change_payment_method.form'
|
||||
sale = fields.Many2One('sale.sale', "Sale", required=True)
|
||||
statement = fields.Many2One('account.statement', 'Statement Journal',
|
||||
domain=[
|
||||
('id', 'in', Eval('statements', [])),
|
||||
],
|
||||
depends=['journals'], required=True)
|
||||
statements = fields.One2Many('account.statement', None,
|
||||
'Allowed Statement', readonly=True)
|
||||
payment = fields.Many2One(
|
||||
'account.statement.line', "Payment", required=True,
|
||||
domain=[('sale.id', '=', Eval('sale'))])
|
||||
|
||||
|
||||
class ChangePaymentMethod(Wizard):
|
||||
'Change Payments Method for the sale'
|
||||
__name__ = 'sale.change_payment_method'
|
||||
start = StateView('sale.change_payment_method.form',
|
||||
'sale_payment.sale_change_payment_method_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Modify', 'modify_payments_', 'tryton-ok',
|
||||
default=True),])
|
||||
|
||||
modify_payments_ = StateTransition()
|
||||
|
||||
def default_start(self, fields):
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
User = pool.get('res.user')
|
||||
Statement = pool.get('account.statement')
|
||||
sale = Sale(Transaction().context['active_id'])
|
||||
user = User(Transaction().user)
|
||||
device = user.sale_device
|
||||
|
||||
if device:
|
||||
journals = [j.id for j in device.journals]
|
||||
draft_statements = Statement.search([
|
||||
('journal', 'in', journals),
|
||||
('state', '=', 'draft'),
|
||||
], order=[
|
||||
('create_date', 'ASC'),
|
||||
])
|
||||
|
||||
return {
|
||||
'sale': sale.id,
|
||||
'statements': [statement.id for statement in draft_statements],
|
||||
}
|
||||
|
||||
def transition_modify_payments_(self):
|
||||
self.start.payment.statement = self.start.statement.id
|
||||
self.start.payment.save()
|
||||
|
||||
return 'end'
|
||||
|
||||
|
||||
class SalePaymentForm(ModelView):
|
||||
'Sale Payment Form'
|
||||
__name__ = 'sale.payment.form'
|
||||
|
||||
Reference in New Issue
Block a user