Skip to content

Commit

Permalink
[IMP] purchase: add section and note on order line
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravi Gadhia authored and Feyensv committed Jul 10, 2019
1 parent 14812f4 commit 80dfcc6
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 64 deletions.
25 changes: 20 additions & 5 deletions addons/l10n_in_purchase/views/report_purchase_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@
<odoo>

<template id="gst_report_purchaseorder_document_inherit" inherit_id="purchase.report_purchaseorder_document">
<xpath expr="//tr[@t-foreach='o.order_line']/td[1]" position="replace">

<td><span t-field="line.name"/><t t-if="line.product_id.l10n_in_hsn_code and o.company_id.country_id.code == 'IN'"><h6><strong class="ml16">HSN/SAC Code:</strong> <span t-field="line.product_id.l10n_in_hsn_code"/></h6></t></td>
<xpath expr="//t[@t-foreach='o.order_line']//td[@id='product']" position="replace">
<td>
<span t-field="line.name"/>
<t t-if="line.product_id.l10n_in_hsn_code and o.company_id.country_id.code == 'IN'">
<h6>
<strong class="ml16">HSN/SAC Code:</strong>
<span t-field="line.product_id.l10n_in_hsn_code"/>
</h6>
</t>
</td>
</xpath>
</template>

<template id="gst_report_purchasequotation_document_inherit" inherit_id="purchase.report_purchasequotation_document">
<xpath expr="//tr[@t-foreach='o.order_line']/td[1]" position="replace">
<td><span t-field="order_line.name"/><t t-if="order_line.product_id.l10n_in_hsn_code and o.company_id.country_id.code == 'IN'"><h6><strong class="ml16">HSN/SAC Code:</strong> <span t-field="order_line.product_id.l10n_in_hsn_code"/></h6></t></td>
<xpath expr="//t[@t-foreach='o.order_line']//td[@id='product']" position="replace">
<td>
<span t-field="order_line.name"/>
<t t-if="order_line.product_id.l10n_in_hsn_code and o.company_id.country_id.code == 'IN'">
<h6>
<strong class="ml16">HSN/SAC Code:</strong>
<span t-field="order_line.product_id.l10n_in_hsn_code"/>
</h6>
</t>
</td>
</xpath>
</template>

Expand Down
2 changes: 1 addition & 1 deletion addons/purchase/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _onchange_purchase_auto_complete(self):
# Copy purchase lines.
po_lines = self.purchase_id.order_line - self.line_ids.mapped('purchase_line_id')
new_lines = self.env['account.move.line']
for line in po_lines:
for line in po_lines.filtered(lambda l: not l.display_type):
new_line = new_lines.new(line._prepare_account_move_line(self))
new_line.account_id = new_line._get_computed_account()
new_line._onchange_price_subtotal()
Expand Down
29 changes: 24 additions & 5 deletions addons/purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _compute_date_planned(self):
for order in self:
min_date = False
for line in order.order_line:
if not min_date or line.date_planned < min_date:
if not min_date or line.date_planned and line.date_planned < min_date:
min_date = line.date_planned
if min_date:
order.date_planned = min_date
Expand Down Expand Up @@ -360,7 +360,7 @@ def _add_supplier_to_product(self):
for line in self.order_line:
# Do not add a contact as a supplier
partner = self.partner_id if not self.partner_id.parent_id else self.partner_id.parent_id
if partner not in line.product_id.seller_ids.mapped('name') and len(line.product_id.seller_ids) <= 10:
if line.product_id and partner not in line.product_id.seller_ids.mapped('name') and len(line.product_id.seller_ids) <= 10:
currency = partner.property_purchase_currency_id or self.env.company.currency_id
supplierinfo = {
'name': partner.id,
Expand Down Expand Up @@ -431,11 +431,11 @@ class PurchaseOrderLine(models.Model):
sequence = fields.Integer(string='Sequence', default=10)
product_qty = fields.Float(string='Quantity', digits='Product Unit of Measure', required=True)
product_uom_qty = fields.Float(string='Total Quantity', compute='_compute_product_uom_qty', store=True)
date_planned = fields.Datetime(string='Scheduled Date', required=True, index=True)
date_planned = fields.Datetime(string='Scheduled Date', index=True)
taxes_id = fields.Many2many('account.tax', string='Taxes', domain=['|', ('active', '=', False), ('active', '=', True)])
product_uom = fields.Many2one('uom.uom', string='Unit of Measure', required=True, domain="[('category_id', '=', product_uom_category_id)]")
product_uom = fields.Many2one('uom.uom', string='Unit of Measure', domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
product_id = fields.Many2one('product.product', string='Product', domain=[('purchase_ok', '=', True)], change_default=True, required=True)
product_id = fields.Many2one('product.product', string='Product', domain=[('purchase_ok', '=', True)], change_default=True)
product_type = fields.Selection(related='product_id.type', readonly=True)
price_unit = fields.Float(string='Unit Price', required=True, digits='Product Price')

Expand Down Expand Up @@ -465,6 +465,19 @@ class PurchaseOrderLine(models.Model):
currency_id = fields.Many2one(related='order_id.currency_id', store=True, string='Currency', readonly=True)
date_order = fields.Datetime(related='order_id.date_order', string='Order Date', readonly=True)

display_type = fields.Selection([
('line_section', "Section"),
('line_note', "Note")], default=False, help="Technical field for UX purpose.")


_sql_constraints = [
('accountable_required_fields',
"CHECK(display_type IS NOT NULL OR (product_id IS NOT NULL AND product_uom IS NOT NULL))",
"Missing required fields on accountable purchase order line."),
('non_accountable_null_fields',
"CHECK(display_type IS NULL OR (product_id IS NULL AND price_unit = 0 AND product_uom_qty = 0 AND product_uom IS NULL))",
"Forbidden values on non-accountable purchase order line"),
]
@api.depends('product_qty', 'price_unit', 'taxes_id')
def _compute_amount(self):
for line in self:
Expand Down Expand Up @@ -545,6 +558,9 @@ def _inverse_qty_received(self):

@api.model
def create(self, values):
if values.get('display_type', self.default_get(['display_type'])['display_type']):
values.update(product_id=False, price_unit=0, product_uom_qty=0, product_uom=False)

line = super(PurchaseOrderLine, self).create(values)
if line.order_id.state == 'purchase':
msg = _("Extra line with %s ") % (line.product_id.display_name,)
Expand All @@ -553,6 +569,9 @@ def create(self, values):

@api.multi
def write(self, values):
if 'display_type' in values and self.filtered(lambda line: line.display_type != values.get('display_type')):
raise UserError("You cannot change the type of a purchase order line. Instead you should delete the current line and create a new line of the proper type.")

if 'product_qty' in values:
for line in self:
if line.order_id.state == 'purchase':
Expand Down
75 changes: 53 additions & 22 deletions addons/purchase/report/purchase_order_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,59 @@
</tr>
</thead>
<tbody>
<tr t-foreach="o.order_line" t-as="line">
<td>
<span t-field="line.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, line.taxes_id))"/>
</td>
<td class="text-center">
<span t-field="line.date_planned"/>
</td>
<td class="text-right">
<span t-field="line.product_qty"/>
<span t-field="line.product_uom.name" groups="uom.group_uom"/>
</td>
<td class="text-right">
<span t-field="line.price_unit"/>
</td>
<td class="text-right">
<span t-field="line.price_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
<t t-set="current_subtotal" t-value="0"/>
<t t-foreach="o.order_line" t-as="line">
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>

<tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
<t t-if="not line.display_type">
<td id="product">
<span t-field="line.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, line.taxes_id))"/>
</td>
<td class="text-center">
<span t-field="line.date_planned"/>
</td>
<td class="text-right">
<span t-field="line.product_qty"/>
<span t-field="line.product_uom.name" groups="uom.group_uom"/>
</td>
<td class="text-right">
<span t-field="line.price_unit"/>
</td>
<td class="text-right">
<span t-field="line.price_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</t>
<t t-if="line.display_type == 'line_section'">
<td colspan="99" id="section">
<span t-field="line.name"/>
</td>
<t t-set="current_section" t-value="line"/>
<t t-set="current_subtotal" t-value="0"/>
</t>
<t t-if="line.display_type == 'line_note'">
<td colspan="99" id="note">
<span t-field="line.name"/>
</td>
</t>
</tr>
<t t-if="current_section and (line_last or o.order_line[line_index+1].display_type == 'line_section')">
<tr class="is-subtotal text-right">
<td colspan="99" id="subtotal">
<strong class="mr16">Subtotal</strong>
<span
t-esc="current_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
</tr>
</t>
</t>
</tbody>
</table>

Expand Down
33 changes: 21 additions & 12 deletions addons/purchase/report/purchase_quotation_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,27 @@
</tr>
</thead>
<tbody>
<tr t-foreach="o.order_line" t-as="order_line">
<td>
<span t-field="order_line.name"/>
</td>
<td class="text-center">
<span t-field="order_line.date_planned"/>
</td>
<td class="text-right">
<span t-field="order_line.product_qty"/>
<span t-field="order_line.product_uom" groups="uom.group_uom"/>
</td>
</tr>
<t t-foreach="o.order_line" t-as="order_line">
<tr t-att-class="'bg-200 font-weight-bold o_line_section' if order_line.display_type == 'line_section' else 'font-italic o_line_note' if order_line.display_type == 'line_note' else ''">
<t t-if="not order_line.display_type">
<td id="product">
<span t-field="order_line.name"/>
</td>
<td class="text-center">
<span t-field="order_line.date_planned"/>
</td>
<td class="text-right">
<span t-field="order_line.product_qty"/>
<span t-field="order_line.product_uom" groups="uom.group_uom"/>
</td>
</t>
<t t-else="">
<td colspan="99" id="section">
<span t-field="order_line.name"/>
</td>
</t>
</tr>
</t>
</tbody>
</table>

Expand Down
23 changes: 22 additions & 1 deletion addons/purchase/views/portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@
<strong>Subtotal</strong>
</div>
</div>
<t t-set="current_subtotal" t-value="0"/>
<t t-foreach="order.order_line" t-as="ol">
<div class="row purchases_vertical_align">
<t t-set="current_subtotal" t-value="current_subtotal + ol.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<t t-set="current_subtotal" t-value="current_subtotal + ol.price_total" groups="account.group_show_line_subtotals_tax_included"/>
<div t-if="not ol.display_type" class="row purchases_vertical_align">
<div class="col-lg-1 text-center">
<img t-att-src="image_data_uri(resize_to_48(ol.product_id.image))" alt="Product"/>
</div>
Expand All @@ -115,6 +118,24 @@
<span t-field="ol.price_subtotal" t-options='{"widget": "monetary", "display_currency": order.currency_id}'/>
</div>
</div>
<div t-else="" class="col-lg-12 bg-light">
<span t-esc="ol.name"/>
</div>
<t t-if="ol.display_type == 'line_section'">
<t t-set="current_section" t-value="ol"/>
<t t-set="current_subtotal" t-value="0"/>
</t>
<t t-if="current_section and (ol_last or order.order_line[ol_index+1].display_type == 'line_section')">
<div class="row">
<div class="col-lg-10 text-right">Subtotal</div>
<div class="col-lg-2 text-right">
<span
t-esc="current_subtotal"
t-options='{"widget": "monetary", "display_currency": order.currency_id}'
/>
</div>
</div>
</t>
</t>

<hr/>
Expand Down

0 comments on commit 80dfcc6

Please sign in to comment.