Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
15015 Vistas

i want to restrict user to print report Quotation / Order of sale until/unless state == 'sale'

if state not in sale need to show message to user "you can not Print report until sale confirmation.

my question is base on two way .

1) Report hide from print menu (if it's not possible ) see option 2

2) report show in print menu but restrict user until state =='sale'

Avatar
Descartar
Mejor respuesta

Hi Usman,

I am not sure about 1st point but you can do the 2nd point. For that you need to override the controller class (ReportController) of the web module and override report download method (​report_download​) in which you can write your code to restrict the user.

In the controller method, pass exception message like this.

Avatar
Descartar
Mejor respuesta

Hello Usman,

Answer for option 2).

See ref. code already existed in v12:

you can raise warning in below method based on condition as you want.because this method is calling before printing the report file.and after clicking on report menu.

class SaleOrderReportProforma(models.AbstractModel):
_name = 'report.sale.report_saleproforma'
_description = 'Proforma Report'

@api.multi
def _get_report_values(self, docids, data=None):
docs = self.env['sale.order'].browse(docids)
return {
'doc_ids': docs.ids,
'doc_model': 'sale.order',
'docs': docs,
'proforma': True
}​

Thanks,
Dipak

Avatar
Descartar
Autor

Dipak my report is not Proforma report my report name is Qoutation / Sale ...is it possible this code i can inherit and get state from self and put condition on it ...

pls write some more help

> Your report name is "Quotation / Order" as you mentioned in your question.

> the code i given is useful.and yes please use 'docs' variable instead of 'self' if you can see in code 'docs' variable already contains recordset. so iterate it and check your condition of state.

Autor

```

class SaleOrderReportProforma(models.AbstractModel):

_inherit = 'report.sale.report_saleproforma'

@api.multi

def _get_report_values(self, docids, data=None):

res = super(SaleOrderReportProforma, self)._get_report_values(self, docids, data=None)

docs = self.env['sale.order'].browse(docids)

for doc in docs:

if doc.state != 'sale':

raise exceptions.ValidationError('Please approve the order to print the report.')

else:

return res

```

it's not working not giving error install successfully ... where i'm wrong ?

Hello Usman,

I tested below code , its working well.

Please try below code:

class SaleOrderReport(models.AbstractModel):

_name = 'report.sale.report_saleorder'

_description = 'Sale order Report'

@api.multi

def _get_report_values(self, docids, data=None):

docs = self.env['sale.order'].browse(docids)

for doc in docs:

if doc.state != 'sale':

raise exceptions.ValidationError('Please approve the order to print the report.')

return {

'doc_ids': docs.ids,

'doc_model': 'sale.order',

'docs': docs,

'proforma': True

}

replace ...

_inherit = 'report.sale.report_saleproforma'

with this code ..

_name = 'report.sale.report_saleorder'

@Dipek I tried your code, it works but it prints empty report for me.

could you please let me know how to replace @api.multi in v14

Mejor respuesta

* Hide report on print 
* Now add button on object with states option to print report (For sale print button is already there just show it in "Sale" state only)

Avatar
Descartar
Autor

this is last option

but any logic how i can achive my goal ?

This is the simplest option to achieve your goal.

Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 20
2585
1
feb 22
2408
1
abr 25
1405
1
feb 25
468
0
may 20
2395