Commit 9cca93f4 authored by Nhomar Hernández's avatar Nhomar Hernández 💬
Browse files

[IMP] purchase_rfq_xls: Redisign report template, Case when no ID.

1. Added internal code and vendor code.
2. Added minimal logic when product code and vendor code found.
3. Welcome to buttons Create and Add, Add and Search in web (Dummy yet
not working).
4. Form view for line of elements on wizard.

[IMP] purchase_rfq_xls: Redesign report template.

1. Added links to actions.
2. Better formatting the header information.
3. Adjusted properly the methods in order to adjust the new format.
4. For space reasons in the report we need to use ID instead xml_id.
5. Just comment temporal the diff management
parent 2422d306
......@@ -8,12 +8,6 @@
<attribute name="t-att-data-report-header-spacing">data_report_header_spacing if data_report_header_spacing else None</attribute>
<attribute name="t-att-data-report-dpi">data_report_dpi if data_report_dpi else None</attribute>
</xpath>
<!-- Add report style -->
<xpath expr="//head" position="inside">
<style type="text/css">
<t t-call="purchase_rfq_xls.style"/>
</style>
</xpath>
<!-- Remove conflicting style -->
<xpath expr="//head/link[@href='/web/static/src/css/full.css']" position="replace"></xpath>
</template>
......@@ -25,110 +19,10 @@
</t>
</template>
<template id="purchase_rfq_xls.style">
table {
border-collapse: separated;
}
table, th, td {
border: 2px solid white;
}
table.basic_table{
text-align:left;
}
.dest_address {
font-size:12pt;
margin-left:0;
text-align:left;
line-height:80%;
padding-top:0px
}
.prueba{
color:black;
background-color:#dcdcdc;
}
.celdaTotalTitulo{
font-size:11pt;
text-align:left;
font-weight:bold;
font-family:Arial,Helvetica,sans-serif;
background-color:#dcdcdc;
}
.celdaTotal{
font-size:10pt;
font-style:normal;
font-family: FreeMono;
text-align:right;
font-weight:bold;
background-color:#dcdcdc;
}
.celdaDetailTitulo{
font-style:italic;
font-size:11pt;
text-align:left;
font-family:Arial,Helvetica,sans-serif;
background-color:#F5F5F5;
}
.celdaDetail{
font-size:10pt;
font-family: monospace;
text-align:right;
background-color:#F5F5F5;
}
.celdaDetailLeft{
font-size:10pt;
font-family: monospace;
text-align:left;
background-color:#F5F5F5;
}
.celdaAbstractTotal{
font-size:11pt;
text-align:left;
font-family:Arial,Helvetica,sans-serif;
background-color:#EAEAEA;
}
.celdaTituloTabla{
font-size:11pt;
text-align:left;
font-family:Arial,Helvetica,sans-serif;
background-color:#620400;
color:#FFFFFF;
}
.celdaAbstract{
font-size:10pt;
font-family: monospace;
text-align:right;
background-color:#EAEAEA;
}
div.td_company{
font-size:12pt;
margin-left:0;
font-weight:bold;
font-family:Arial,Helvetica,sans-serif;
}
div.td_company_title{
font-size:22pt;
margin-left:0;
font-weight:bold;
font-family:Arial,Helvetica,sans-serif;
}
</template>
<template id="purchase_rfq_xls.external_layout">
<!-- Multicompany -->
<t t-call="purchase_rfq_xls.minimal_layout">
</t>
<t t-if="o and 'company_id' in o">
<t t-set="company" t-value="o.company_id"></t>
</t>
......@@ -138,100 +32,6 @@
<t t-raw="0" />
</template>
<template id="purchase_rfq_xls.external_layout_header">
<!--VARIABLES TO BE USED LATER-->
<div class="header">
<table width="100%">
<tr>
<td width="30%">
<div>
<img t-if="o.company_id.logo" t-att-src="'data:image/png;base64,%s' % o.company_id.logo" style="max-height: 45px;"/>
</div>
</td>
<td width="70%">
<table style="width: 100%; text-align:center;" id="table_header">
<tr><td></td></tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
<span t-esc="datetime.now().strftime('%d/%m/%Y')"/>
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
P.O.#:
</td>
<td>
<span t-field="o.name" />
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Creation Date:
</td>
<td>
<span t-field="o.date_order" t-field-options='{"format": "dd/MM/yyyy"}'/>
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Creation By:
</td>
<td>
<span t-field="o.company_id.name" />
</td>
</tr>
<!-- (if) Get destinatary address -->
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Ext. P.O.#:
</td>
<td>
<span t-field="o.partner_ref" />
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Reference:
</td>
<td>
<span t-field="o.origin" />
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Expected Date:
</td>
<td>
<span t-field="o.minimum_planned_date" t-field-options='{"format": "dd/MM/yyyy"}'/>
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Ship Via:
</td>
<td>
<span t-field="o.picking_type_id.warehouse_id.name" />
</td>
</tr>
<tr><td></td><td></td><td></td><td></td>
<td class="text-right">
Cust.#:
</td>
<td>
<span t-field="o.partner_id.ref" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="basic_table" width="100%" border="0">
<thead>
</thead>
</table>
</div>
</template>
<template id="purchase_rfq_xls.external_layout_footer">
<div class="footer">
<div class="text-right" style="border-top: 1px solid lightGrey;">
......
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="purchase_rfq_xls.external_layout_header">
<!--VARIABLES TO BE USED LATER-->
<div class="page-header">
<ul class="nav nav-pills">
<li role="presentation"><a target="new" t-attf-href="/purchase_rfq_xls/download/{{o.id}}" class="btn btn-link">Download in Excel</a></li>
<li role="presentation"><a target="new" t-attf-href="/report/pdf/purchase_rfq_xls.report_template/{{o.id}}" class="btn btn-link">Download in PDF</a></li>
<li role="presentation"><a href="#" class="btn btn-link">Resend by Email</a></li>
<li role="presentation"><a target="new" t-attf-href="/purchase_rfq_xls/upload/{{o.id}}" class="btn btn-link">Upload Excel</a></li>
<li role="presentation"><a href="/purchase_rfq_xls/report/help" class="btn btn-link">Help</a></li>
</ul>
</div>
</template>
<template id="report_document">
<t t-call="purchase_rfq_xls.external_layout">
<!--VARIABLES TO BE USED LATER-->
<!-- CALLING HEADER and FOOTER -->
<t t-call="purchase_rfq_xls.external_layout_header"/>
<t t-call="purchase_rfq_xls.external_layout_footer"/>
<div class="page">
<table class="basic_table" width="100%" id="table_body">
<t t-call="purchase_rfq_xls.external_layout_header"/>
<table class="table table-condensed table-hover table-bordered" id="table_body">
<thead>
<tr>
<th>Number</th>
<th><span t-field="o.name"/></th>
<th>Sale Order</th>
<th><span t-field="o.partner_ref"/></th>
<th>Origin</th>
<th><span t-field="o.origin"/></th>
<th>Order State</th>
<th><span t-field="o.state"/></th>
</tr>
<tr>
<th>Printed date</th>
<th><span t-esc="datetime.now().strftime('%d/%m/%Y')"/></th>
<th>Order Date</th>
<th><span t-field="o.date_order" t-field-options='{"format": "dd/MM/yyyy"}'/></th>
<th>Expected Date</th>
<th><span t-field="o.minimum_planned_date" t-field-options='{"format": "dd/MM/yyyy"}'/></th>
<th>Warehouse</th>
<th><span t-field="o.picking_type_id.warehouse_id.name"/></th>
</tr>
<tr>
<th>Ship To</th>
<th colspan="7"><span t-field="o.picking_type_id.warehouse_id.partner_id.display_name" /></th>
</tr>
<tr>
<th>Vendor</th>
<th>TODO: PARTNER_CODE</th>
<th colspan="6"><span t-field="o.partner_id.display_name"/></th>
</tr>
<tr>
</tr>
<tr>
</tr>
</thead>
</table>
<table class="table table-condensed table-hover table-bordered" id="table_body">
<thead>
<tr>
<td><strong>External ID</strong></td>
<td><strong>Model</strong></td>
<td><strong>Vendor Code</strong></td>
<td><strong>Description</strong></td>
<td class="text-center"><strong>Qty</strong></td>
<td class="text-right"><strong>Cost</strong></td>
<th>ID</th>
<th>Product Code</th>
<th>Vendor Code</th>
<th>Description</th>
<th>Date Planned</th>
<th class="text-center">Qty</th>
<th class="text-center">Last Cost</th>
<th class="text-center">Cost Proposed</th>
</tr>
</thead>
<tbody>
<tr t-foreach="o.order_line" t-as="order_line">
<td>
<span t-field="order_line.xml_id"/>
<span t-field="order_line.id"/>
</td>
<td>
<span t-field="order_line.product_id.default_code"/>
......@@ -33,12 +79,18 @@
<span t-field="order_line.vendor_code"/>
</td>
<td>
<span t-field="order_line.product_id.name"/>
<span t-field="order_line.name"/>
</td>
<td>
<span t-field="order_line.date_planned"/>
</td>
<td class="text-center">
<span t-field="order_line.product_qty"/>
</td>
<td class="text-right"></td>
<td class="text-center">
<span t-field="order_line.price_unit"/>
</td>
<td class="text-center"></td>
</tr>
</tbody>
</table>
......@@ -49,7 +101,7 @@
<template id="report_template">
<t t-call="purchase_rfq_xls.html_container">
<t t-set="doc_id" t-value="doc_ids[0]"/>
<t t-raw="translate_doc(doc_id, doc_model, 'company_id.partner_id.lang', 'purchase_rfq_xls.report_document')"/>
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'purchase_rfq_xls.report_document')"/>
</t>
</template>
</data>
......
......@@ -19,17 +19,45 @@
</group>
<separator/>
<group string="Import successfully done" states="success,success2">
<p states="success">All was done properly but you need
yet the following items should be added to the P.O.
manually.</p>
<p states="success2">No differences to report!</p>
<p class="oe_grey" states="success">All was done
properly but you need yet the following items should be
added to the P.O. manually.</p>
<p class="oe_grey" states="success2">No differences to
report!</p>
<group string="Relevant Information">
<field name="line_ids" nolabel="1" readonly="1">
<tree delete='0'>
<tree>
<field name="product"/>
<field name="product_tmpl"/>
<field name="internal_code"/>
<field name="vendor_code"/>
<field name="description"/>
<field name="cost"/>
<button name="add_pol" string="Add" type="object"
attrs="{'invisible': [('product', '=', False)]}"/>
<button name="create_product_add_pol" string="Create and Add"
attrs="{'invisible': [('product', '!=', False), ('product_tmpl', '=', False)]}"
type="object"/>
<button name="open_in_web" string="Search in Web" type="object"/>
</tree>
<form>
<group>
<field name="product"/>
<field name="product_tmpl"/>
<field name="internal_code"/>
<field name="vendor_code"/>
<field name="description"/>
<field name="cost"/>
</group>
<footer>
<button name="add_pol" string="Add" type="object"
attrs="{'invisible': [('product', '=', False)]}"/>
<button name="create_product_add_pol" string="Create and Add"
attrs="{'invisible': [('product', '!=', False), ('product_tmpl', '=', False)]}"
type="object"/>
<button name="open_in_web" string="Search in Web" type="object"/>
</footer>
</form>
</field>
</group>
</group>
......
......@@ -38,7 +38,7 @@ except ImportError:
class PurchaseQuotationWizard(models.TransientModel):
_description = 'Purchase Quotation'
_name = 'purchase.quotation.wizard'
_col_start = "External ID"
_col_start = "ID"
@api.depends()
def _get_purchase(self):
......@@ -49,11 +49,11 @@ class PurchaseQuotationWizard(models.TransientModel):
template_action = fields.Selection([
('export', "Get a quotation template without prices"),
('import', "Update a quotation prices"),
], default='import',
help='Get a quotation template without prices: Simply download the '
'template xls.\n'
'Update a quotation: Given a filled template upload it and update '
'the prices sent by supplier')
], default='import', help='Get a quotation template without prices: '
'Simply download the template xls. \n '
'Update a quotation: Given a '
'filled template upload it and update the '
'prices sent by supplier')
xls_file = fields.Binary('Valid XLS file')
xls_name = fields.Char()
state = fields.Selection([('form', 'form'),
......@@ -91,8 +91,6 @@ class PurchaseQuotationWizard(models.TransientModel):
data = {}
if isinstance(price, float) and isinstance(qty, float):
data.update({'price_unit': price, 'product_qty': qty})
if order_line.product_qty <= qty:
data['price_unit'] = price
return order_line.write(data)
return False
......@@ -116,14 +114,15 @@ class PurchaseQuotationWizard(models.TransientModel):
"""
self.ensure_one()
context = dict(self._context)
purchase = self.purchase
fname = '/tmp/%s' % (self.xls_name)
# I go directly to the sheet, because the contraint already validated
# which is the proper format for the sheet.
sheet = xlrd.open_workbook(fname).sheet_by_index(0)
eof = self.get_xls_eof(sheet)
# First col header on Qweb report: template.xml
can_start, done_ids, new_products = False, [], []
can_start = False
done_ids = self.env['purchase.order.line']
new_products = []
for row in range(eof):
if self._col_start == sheet.cell_value(row, 0):
can_start = True
......@@ -131,29 +130,58 @@ class PurchaseQuotationWizard(models.TransientModel):
if not can_start:
continue
# Proposed product Quantity
product_qty = sheet.cell_value(row, 4)
price_unit = sheet.cell_value(row, 5)
order_line = self.env['purchase.order.line']
product = self.env['product.supplierinfo']
prod = self.env['product.product']
values = dict(identifier=sheet.cell_value(row, 0),
internal_code=sheet.cell_value(row, 1),
vendor_code=sheet.cell_value(row, 2),
description=sheet.cell_value(row, 3),
date_planned=sheet.cell_value(row, 4),
product_qty=sheet.cell_value(row, 5),
# cell on column 6 is the price that I know, then
# just ignoring it.
price_unit=sheet.cell_value(row, 7))
# Using the External ID I try to get the order
order_line = self.env.ref(sheet.cell_value(row, 0))
if values['identifier']:
# If identifier: we will try the line as it is (no code and/or
# any other check more than the qty and price).
order_line = done_ids.search([('id', '=',
int(values['identifier']))],
limit=1)
if values['vendor_code'] and not values['identifier']:
# If no identifier: we will try to look by internal code.
product = product.search([('product_code', '=',
values['vendor_code'])])
if values['internal_code'] and not values['identifier']:
prod = prod.search([('default_code', '=',
values['internal_code'])])
if order_line:
self._update_price(order_line, price_unit, product_qty)
done_ids.append(order_line.id)
self._update_price(order_line,
values['price_unit'],
values['product_qty'])
done_ids += order_line
if not order_line:
new_products.append((0, 0, {
'vendor_code': sheet.cell_value(row, 2),
'description': sheet.cell_value(row, 3),
'cost': price_unit,
# Vendor Code
'product': prod,
'product_tmpl': product,
'vendor_code': values['vendor_code'],
'internal_code': values['internal_code'],
'description': values['description'],
'cost': values['price_unit'],
'product_qty': values['product_qty'],
}))
if done_ids:
order_line_done = self.env['purchase.order.line'].browse(done_ids)
# if done_ids:
# intersect objects and unlink diff
order_line_diff = purchase.order_line - order_line_done
# order_line_diff = purchase.order_line - done_ids
# TODO: I think they should not be deleted.
# order_line_diff.unlink()
self.write({'state': 'success2'})
if new_products:
self.write({'state': 'success', 'line_ids': new_products})
self.write({
'state': 'success',
'line_ids': new_products
})
action = self.env.ref('purchase_rfq_xls.action_purchase_quotation')
return action.with_context(context).read([])
......@@ -174,8 +202,13 @@ class PurchaseQuotationWizard(models.TransientModel):
class PurchaseQuotationWizardLine(models.TransientModel):
_description = 'Purchase Quotation Details'
_name = 'purchase.quotation.wizard.line'
_rec_name = 'description'
description = fields.Char()
vendor_code = fields.Char()
internal_code = fields.Char()
wizard_id = fields.Many2one('purchase.quotation.wizard')
product = fields.Many2one('product.product')
product_tmpl = fields.Many2one('product.template')
cost = fields.Float()
product_qty = fields.Float()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment