Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
14985 Lượt xem

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'

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả

```

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

Câu trả lời hay nhất

* 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)

Ảnh đại diện
Huỷ bỏ
Tác giả

this is last option

but any logic how i can achive my goal ?

This is the simplest option to achieve your goal.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 20
2583
1
thg 2 22
2401
1
thg 4 25
1386
1
thg 2 25
465
0
thg 5 20
2388