Skip to Content
Menu
This question has been flagged

I want to see notes field of the purchase order in the report too. I have added the field by inheritance once and also by changing the purchase module code but i am getting an error with report . All other fields are working and fetching data. It is basically a purchase comparison report. Please help and tell me what i am doing wrong and what should i do.

here is my code for notes field


<t t-foreach="data" t-as="question">
<tr class="row2">
<td class="table_td">
<span t-esc="i" />
</td>
<td style="border:solid #d1cfcf 1px;padding:5px;line-height: 13px;">
<span t-esc="question['product_name']" />
</td>
<td class="table_td">
<span t-esc="question['uom']" />
</td>
<td class="table_td">
<span t-esc="question['qty']" />
</td>
<t t-foreach="data" t-as="question">
<t t-foreach="question['amt']" t-as="amount">
<td class="table_td">
<span t-esc="amount['price']" />
</td>
<td class="table_td">
<span t-esc="amount['total_amount']" />
</td>
<td class="table_td">
<span t-esc="amount['notes']" />
</td>

</t>
everything is working except notes. The error i am getting is
error 

'notes'
Traceback (most recent call last):
  File "C:\odoo\odoo\odoo\addons\base\ir\ir_qweb\qweb.py", line 343, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_1059_1060
  File "<template>", line 2, in body_call_content_1059
  File "<template>", line 74, in foreach_1058
  File "<template>", line 88, in foreach_1057
  File "<template>", line 89, in foreach_1056
KeyError: 'notes'

Error to render compiling AST
KeyError: 'notes'
Template: 1059
Path: /templates/t/t/div/div/div/div[4]/table/thead/tr[2]/t[3]/tr/t/t[1]/td[3]/span
Node: <span t-esc="amount['notes']"/>
Avatar
Discard

Hope this will helps, https://goo.gl/8HgnCF

Best Answer

The error message saying, there is no key argument 'notes' in the dictinory 'amount'. Make sure you added the key 'notes' in the dictionary in python funciton. 

Note: Please post complete source code including python code. 

Hope this will help you.

Avatar
Discard
Author

Thanks for replying. Can you please give me an example of how to add notes in the dictionary?

Please post complete code of the report both xml and python.

Author

its an addon which i am changing named as "Purchase comparison chart".

main.py includes

from odoo import http

from odoo.http import request

class ValidateBid(http.Controller):

@http.route(['/purchase_comparison_chart/purchase_comparison/<model("purchase.requisition"):purchase_requisition_id>'], type='http', auth='public', website=True)

def purchase_comparison(self, purchase_requisition_id, **post):

supplier_ids = []; product_ids=[]; values = []; amt = []; number = []; supplier_id = []

counts = 1

for record in request.env['purchase.order'].sudo().search([('requisition_id', '=', purchase_requisition_id.id)]):

# Append supplier

supplier_ids.append({'supplier_id':record.partner_id.id, 'sname':record.partner_id.name})

supplier_id.append(record.partner_id.id)

number.append(counts)

# Append Products and quantity

counts +=1

for line in record.order_line:

if values:

if line.product_id.id not in product_ids:

product_ids.append(line.product_id.id)

values.append({'product_id':line.product_id.id, 'product_name':line.product_id.name, 'price':line.price_unit, 'uom':line.product_id.uom_po_id.name, 'qty':line.product_qty, 'name':line.name})

else:

product_ids.append(line.product_id.id)

values.append({'product_id':line.product_id.id,'product_name':line.product_id.name, 'price':line.price_unit, 'uom':line.product_id.uom_po_id.name,'qty':line.product_qty, 'name':line.name})

count = 0; supplier_amount_total = []; no_of_col = 2 ; even_number = [] ; odd_number = []

# Append amount based on the products and supplier

for separate_values in values:

for suppliers in supplier_ids:

for record in request.env['purchase.order'].sudo().search([('requisition_id', '=', purchase_requisition_id.id),('partner_id', '=',suppliers['supplier_id'])]):

for po_line in request.env['purchase.order.line'].search([('order_id', '=', record.id),('product_id', '=',separate_values['product_id'])]):

amt.append({'total_amount':(po_line.product_qty * po_line.price_unit), 'price':po_line.price_unit, 'name': po_line.name})

values[count]['amt'] = amt

count +=1

amt = []

# Generate number to create rows and columns

total_supplier = len(number)

if total_supplier >= 2:

increase_by_supplier = total_supplier * no_of_col

else:

increase_by_supplier = no_of_col

if total_supplier > 1:

total_no = range(1, increase_by_supplier + 1)

supplier_amount_total_1 = list(range(1, increase_by_supplier + 1))

else:

total_no = range(1, increase_by_supplier)

supplier_amount_total_1 = list(range(1, increase_by_supplier))

for c_number in total_no:

if c_number%2 ==0:

even_number.append(c_number)

else:

odd_number.append(c_number)

for record in request.env['purchase.order'].sudo().search([('requisition_id', '=', purchase_requisition_id.id)]):

supplier_amount_total.append(record.amount_total)

# Update the amount in even number position

tcount = 1

for i in even_number:

supplier_amount_total_1[i-1] = supplier_amount_total[tcount-1]

tcount +=1

# Update the supplier id in odd number position

scount = 1

for odd_no in odd_number:

for total in total_no:

if total == odd_no:

supplier_amount_total_1[odd_no-1] = supplier_id[scount-1]

scount +=1

return request.render('purchase_comparison_chart.purchase_comparison', {'data':values, 'supplier':supplier_ids,'purchase_requisition_id':purchase_requisition_id,

'number':number, 'to_no':total_no, 'column_no':even_number, 'supplier_amount_total':supplier_amount_total,

'supplier_amount_total_1':supplier_amount_total_1, 'odd_number':odd_number})

---------------------

python file includes

class PurchaseOrder(models.Model):

_inherit = 'purchase.order.line'

notes = fields.Char(string='Notes')

@api.model

def create(self,vals):

if vals.get('requisition_id'):

purchase_ids = self.env['purchase.order'].search([('requisition_id','=',vals.get('requisition_id'))])

for po_id in purchase_ids:

if vals.get('partner_id') == po_id.partner_id.id:

raise UserError(_('RFQ is available for this purchase agreement for the same vendor'))

return super(PurchaseOrder, self).create(vals)

@api.multi

def write(self, vals):

if vals.get('partner_id') or vals.get('requisition_id'):

purchase_ids = self.env['purchase.order'].search([('requisition_id', '=', vals.get('requisition_id'))])

for po_id in purchase_ids:

if vals.get('partner_id') == po_id.partner_id.id:

raise UserError(_('RFQ is available for this purchase agreement for the same vendor'))

return super(PurchaseOrder, self).write(vals)

class PurchaseRequisition(models.Model):

_inherit = 'purchase.requisition'

print_url = fields.Char("Print link", compute="_compute_url")

def _compute_url(self):

""" Computes a public URL for the purchase comparison """

base_url = '/' if self.env.context.get('relative_url') else self.env['ir.config_parameter'].get_param('web.base.url')

for record in self:

record.print_url = urljoin(base_url, "purchase_comparison_chart/purchase_comparison/%s" % (slugify(record)))

@api.multi

def show_terms_condition(self, value1, value2):

if value1 and value2:

va = str(value1).strip()

terms_condition = self.env['purchase.order'].search([('requisition_id', '=',self.id), ('partner_id', '=', int(va))])

if terms_condition:

return terms_condition.notes

else:

return None

@api.multi

def purchase_comparison(self):

""" Open the website page with the purchase comparison form """

self.ensure_one()

if self.order_count == 0:

raise UserError(_('No RFQ available for the Purchase agreement. Please add some RFQ to compare'))

return {

'type': 'ir.actions.act_url',

'name': "Purchase Comparison Chart",

'target': 'self',

'url': self.with_context(relative_url=True).print_url

}

@api.multi

def print_xl(self):

purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id)])

for rec in purchase_orders:

for line in rec.order_line:

price_unit = line.price_unit

price_subtotal = line.price_subtotal

style2 = xlwt.easyxf('font: name Times New Roman bold on;align: horiz center;', num_format_str='#,##0')

style0 = xlwt.easyxf('font: name Times New Roman bold on;align: horiz right;', num_format_str='#,##0.00')

style1 = xlwt.easyxf('font: name Times New Roman, bold on,height 250; pattern: pattern solid, fore_colour black;', num_format_str='#,##0.00')

workbook = xlwt.Workbook()

sheet = workbook.add_sheet(self.name)

sheet.write_merge(2, 2, 4, 6, 'PURCHASE COMPARISON', style1)

sheet.write(3, 7,'PRC No', style0)

sheet.write(3, 8, self.name, style0)

sheet.write(4, 7, 'Date',style0)

sheet.write(4, 8, self.ordering_date,style0)

sheet.write_merge(6, 6, 0, 1, 'PRODUCT DETAILS', style1)

sheet.write(8, 3, 'S NO',style1)

sheet.write_merge(8, 8, 4, 5, 'MATERIAL',style1)

sheet.write_merge(8, 8, 6, 7, 'UOM',style1)

sheet.write(8, 8, 'QTY',style1)

n = 9; i = 1

for line in self.line_ids:

sheet.write(n, 3, i, style2)

sheet.write_merge(n, n,4,5, line.product_id.name, style0)

sheet.write_merge(n, n,6,7, line.product_uom_id.name, style0)

sheet.write(n,8, line.product_qty, style0)

n +=1; i += 1

ams_time = datetime.now()

date = ams_time.strftime('%m-%d-%Y %H.%M.%S')

filename = ('Report' + '-' + date + '.xls')

workbook.save(filename)

fp = open(filename, "rb")

file_data = fp.read()

attach_id = self.env['report.wizard'].create({'attachment': base64.encodestring(file_data),

'attach_name': 'Report.xls'})

fp.close()

return {

'type': 'ir.actions.act_window',

'name': ('Report'),

'res_model': 'report.wizard',

'res_id': attach_id.id,

'view_type': 'form',

'view_mode': 'form',

'target': 'new',

}

class PaymentWizard(models.TransientModel):

_name = 'report.wizard'

_description = 'Report Details'

attachment = fields.Binary('Excel Report File', nodrop=True, readonly=True)

attach_name = fields.Char('Attachment Name')

---------------------

now i am trying to take the 'name' field in purchase.order.line to use as notes and i am trying to show it on report and as you said i was trying to add it in dictionary too but no success

Author

ok now it is working i am getting the notes field in the report just had to do some styling now. Thank you soo much you helped alot

Best Answer

Hi,  

 I dint understand the exact requirement from your code.By default the Notes we add in the purchase order will be automatically come in the purchase order when we print it. Even though in your code make sure that in each records of question['amt']  there is a field 'notes'.

Avatar
Discard
Author

its a purchase comparison report for the rfqs against each tender. Its a customer requirement that he wants to add a note for each vendor rfq and he wants to print that too.

Related Posts Replies Views Activity
0
Mar 15
2902
4
Nov 24
5238
1
Mar 24
398
3
Sep 23
22661
0
Feb 24
1718