Skip to Content
Menu
This question has been flagged
2 Replies
10563 Views

hello friends ,

inherit the sale module in my new module name = demo, i also override the one method of sale module from sale.order model.i create a new field in in demo module and now i want to set that field by super method and make that field read only..so how can i do that by super method,my code is given below.

class demo (models.Model):

    _inherit = 'sale.order'


    @ api.multi

    def action_confirm (self):

        self.demo_name = "hello"

        return super (demo, self) .action_confirm (self)

    

    demo_name = fields.Char( 'Dnames', readonly = True) 

correct this please and help..

thanks in advance



Avatar
Discard

Look inheritance in models and views: https://goo.gl/fGNfBY

Hope you get an idea.

Author

thank you

Best Answer
class Demo (models.Model):
    _inherit = 'sale.order'
    demo_name = fields.Char( 'Dnames', readonly = True) 
    @api.multi
    def action_confirm(self):
        res = super(Demo, self).action_confirm()
        self.demo_name = "hello"
        return res

Avatar
Discard
Author

thank you friend its work

Best Answer

Hello, I had the same problem yet this solution is not working 

here is my code 

I can't get to the print inside the if active_model == 'sale.order' 


class AccountPaymentNumidoo(models.Model):
_inherit = "account.payment"
# order_line_ids = fields.One2many('sale.order.line', 'payment_id', readonly=True, copy=False, ondelete='restrict')
order_ids = fields.Many2many('sale.order', 'account_order_payment_rel', 'payment_id', 'order_id',
string="Invoices", copy=False, readonly=True,
help="""Technical field containing the invoice for which the payment has been generated.
This does not especially correspond to the invoices reconciled with the payment,
as it can have been generated first, and reconciled later""")
mode_payment = fields.Selection([('especes', 'Espèces'),
('par_cheque', 'Par chèque'),
('virement_bancaire', 'Virement Bancaire'),
('versement', 'Versement Bancaire'),
('traite', 'Traite')])
@api.model
def default_get(self, default_fields):
rec = super(account_payment, self).default_get(default_fields)
active_ids = self._context.get('active_ids') or self._context.get('active_id')
active_model = self._context.get('active_model')
print(active_model)
# Check for selected invoices ids
if not active_ids or active_model != 'account.move' or active_model != 'sale.order':
return rec
if active_model == 'account.move':
invoices = self.env['account.move'].browse(active_ids).filtered(lambda move: move.is_invoice(include_receipts=True))
# Check all invoices are open
if not invoices or any(invoice.state != 'posted' for invoice in invoices):
raise UserError(_("You can only register payments for open invoices"))
# Check if, in batch payments, there are not negative invoices and positive invoices
dtype = invoices[0].type
for inv in invoices[1:]:
if inv.type != dtype:
if ((dtype == 'in_refund' and inv.type == 'in_invoice') or
(dtype == 'in_invoice' and inv.type == 'in_refund')):
raise UserError(
_("You cannot register payments for vendor bills and supplier refunds at the same time."))
if ((dtype == 'out_refund' and inv.type == 'out_invoice') or
(dtype == 'out_invoice' and inv.type == 'out_refund')):
raise UserError(
_("You cannot register payments for customer invoices and credit notes at the same time."))

amount = self._compute_payment_amount(invoices, invoices[0].currency_id, invoices[0].journal_id,
rec.get('payment_date') or fields.Date.today())
rec.update({
'currency_id': invoices[0].currency_id.id,
'amount': abs(amount),
'payment_type': 'inbound' if amount > 0 else 'outbound',
'partner_id': invoices[0].commercial_partner_id.id,
'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
'communication': invoices[0].invoice_payment_ref or invoices[0].ref or invoices[0].name,
'invoice_ids': [(6, 0, invoices.ids)],
})
else:
if active_model == 'sale.order':
print("i aaaaaaaaaaaa ma sale order")
orders = self.env['sale.order'].browse(active_ids).filtered(lambda move: move.is_sale_document(include_receipts=True))
amount=0
rec.update({
'currency_id': orders[0].currency_id.id,
'amount': abs(amount),
'payment_type': 'inbound',
'partner_id': orders[0].commercial_partner_id.id,
#'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
'communication': orders[0].order_payment_ref or orders[0].ref or orders[0].name,
'order_ids': [(6, 0, order.ids)],
})
return rec
account_payment.default_get = default_get

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
20068
1
Sep 23
2935
3
May 23
5509
7
Apr 23
48855
1
Dec 22
7751