Pārlūkot izejas kodu

Módulo para imprimir etiqueta sin precio

SEBAS 2 mēneši atpakaļ
vecāks
revīzija
4ca1c9c3f6

+ 18 - 4
models/product_product.py

@@ -20,7 +20,7 @@
 #
 ##############################################################################
 
-from openerp import models, fields, api, _
+from openerp import models, api
 import logging
 
 _logger = logging.getLogger(__name__)
@@ -30,6 +30,20 @@ class ProductProduct(models.Model):
 
     @api.multi
     def print_labels(self):
-        return self.env['report'].get_action(self,
-                'product_labels.product_label'
-        )
+        # Asegura que se esté procesando un producto correctamente
+        self.ensure_one()
+
+        return self.env['report'].get_action(
+            self,
+            'product_labels.product_label'
+        )
+
+    @api.multi
+    def print_labels_with_price(self):
+        # Asegura que se esté procesando un producto correctamente
+        self.ensure_one()
+
+        return self.env['report'].get_action(
+            self,
+            'product_labels.product_label_with_price'
+        )

BIN
models/product_product.pyc


+ 10 - 1
models/product_template.py

@@ -34,4 +34,13 @@ class ProductTemplate(models.Model):
         return self.env['report'].get_action(
                 self.product_variant_ids,
                 'product_labels.product_label'
-        )
+        )
+
+    @api.multi
+    def print_labels_with_price(self):
+        # Asegura que solo se esté procesando un producto a la vez
+        self.ensure_one()
+        return self.env['report'].get_action(
+            self.product_variant_ids,
+            'product_labels.product_label_with_price'
+        )

BIN
models/product_template.pyc


+ 83 - 28
report/report_product_labels.xml

@@ -2,6 +2,7 @@
 <openerp>
 	<data>
 
+        <!-- Reporte original para la etiqueta del producto -->
         <report
 			id="product.report_product_label"
 			string="Product Label"
@@ -15,46 +16,100 @@
             <field name="paperformat_id" ref="product_labels.paperformat_product_label"/>
         </record>
 
+        <!-- Nuevo reporte para la etiqueta con precio -->
+        <report
+			id="product.report_product_label_with_price"
+			string="Product Label with Price"
+			model="product.product"
+			report_type="qweb-pdf"
+			file="product_label_with_price"
+			name="product_labels.product_label_with_price"
+		/>
+
+        <record id="product.report_product_label_with_price" model="ir.actions.report.xml">
+            <field name="paperformat_id" ref="product_labels.paperformat_product_label"/>
+        </record>
 
+		<!-- Plantilla original -->
 		<template id="product_label">
             <!-- Multicompany -->
             <t t-if="o and 'company_id' in o">
--				<t t-set="company" t-value="o.company_id"/>
--			</t>
--			 <t t-if="not o or not 'company_id' in o">
--				<t t-set="company" t-value="res_company"/>
--			</t>
+				<t t-set="company" t-value="o.company_id"/>
+			</t>
+			<t t-if="not o or not 'company_id' in o">
+				<t t-set="company" t-value="res_company"/>
+			</t>
 
 		    <t t-call="report.html_container">
                 <t t-foreach="docs" t-as="product">
                     <div class="page">
                         <div class="oe_structure"/>
                         <div class="row">
-													<table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse; margin: 0; padding: 0;">
-												    <tr>
-												        <td colspan="2" style="margin: 0; padding: 0;">
-												            <h5 style="margin: 0; padding: 0;">
-												                <span t-field="product.display_name"/>
-
-												            </h5>
-												        </td>
-												    </tr>
-												    <!-- <tr>
-												        <td colspan="2" style="margin: 0; padding: 0;">
-												            <h5 style="margin: 0; padding: 0;"><span>Precio: </span><span t-field="product.lst_price" /></h5>
-												        </td>
-												    </tr> -->
-														<tr style="border: 1px solid black; margin: 0; padding: 0;">
-															<td colspan="2" style="margin: 0; padding: 0;">
-																	<span t-if="product.ean13">
-																			<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="margin-top: 1px; width:70mm; height:13mm; margin: 0; padding: 0;"/>
-																			<h5 style="margin: 0; padding: 0;"><span t-esc="product.ean13" /></h5>
-																	</span>
-															</td>
-													</tr>
-													</table>
+                            <table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse; margin: 0; padding: 0;">
+                                <tr>
+                                    <td colspan="2" style="margin: 0; padding: 0;">
+                                        <h5 style="margin: 0; padding: 0;">
+                                            <span t-field="product.display_name"/>
+                                        </h5>
+                                    </td>
+                                </tr>
+                                <tr style="border: 1px solid black; margin: 0; padding: 0;">
+                                    <td colspan="2" style="margin: 0; padding: 0;">
+                                        <span t-if="product.ean13">
+                                            <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="margin-top: 1px; width:70mm; height:13mm; margin: 0; padding: 0;"/>
+                                            <h5 style="margin: 0; padding: 0;"><span t-esc="product.ean13" /></h5>
+                                        </span>
+                                    </td>
+                                </tr>
+                            </table>
+                        </div>
+                    </div>
+                 </t>
+		    </t>
+		</template>
 
+		<!-- Nueva plantilla con precio -->
+		<template id="product_label_with_price">
+            <!-- Multicompany -->
+            <t t-if="o and 'company_id' in o">
+				<t t-set="company" t-value="o.company_id"/><t t-if="product">
+    <h5><span t-field="product.display_name"/></h5>
+</t>
+			</t>
+			<t t-if="not o or not 'company_id' in o">
+				<t t-set="company" t-value="res_company"/>
+			</t>
 
+		    <t t-call="report.html_container">
+                <t t-foreach="docs" t-as="product">
+                    <div class="page">
+                        <div class="oe_structure"/>
+                        <div class="row">
+                            <table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse; margin: 0; padding: 0;">
+                                <tr>
+                                    <td colspan="2" style="margin: 0; padding: 0;">
+                                        <h5 style="margin: 0; padding: 0;">
+                                            <span t-field="product.display_name"/>
+                                        </h5>
+                                    </td>
+                                </tr>
+                                <!-- Nueva fila para mostrar el precio -->
+                                <tr>
+                                    <td colspan="2" style="margin: 0; padding: 0;">
+                                        <h5 style="margin: 0; padding: 0;">
+                                            <span>Precio: </span><span t-field="product.lst_price" />
+                                        </h5>
+                                    </td>
+                                </tr>
+                                <tr style="border: 1px solid black; margin: 0; padding: 0;">
+                                    <td colspan="2" style="margin: 0; padding: 0;">
+                                        <span t-if="product.ean13">
+                                            <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="margin-top: 1px; width:70mm; height:13mm; margin: 0; padding: 0;"/>
+                                            <h5 style="margin: 0; padding: 0;"><span t-esc="product.ean13" /></h5>
+                                        </span>
+                                    </td>
+                                </tr>
+                            </table>
                         </div>
                     </div>
                  </t>

+ 69 - 34
report/report_product_labels_wizard.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <openerp>
     <data>
-
+        <!-- Report for the original Product Label -->
         <report
             id="report_product_product_label"
             string="Product Label"
@@ -15,6 +15,21 @@
             <field name="paperformat_id" ref="product_labels.paperformat_product_label"/>
         </record>
 
+        <!-- New Report for Product Label with Price -->
+        <report
+            id="report_product_product_label_with_price"
+            string="Product Label with Price"
+            model="product.product.label"
+            report_type="qweb-pdf"
+            file="product_label_with_price"
+            name="product_labels.product_product_label_with_price"
+        />
+
+        <record id="report_product_product_label_with_price" model="ir.actions.report.xml">
+            <field name="paperformat_id" ref="product_labels.paperformat_product_label"/>
+        </record>
+
+        <!-- Original Template -->
         <template id="product_product_label">
             <t t-call="report.html_container">
                 <t t-foreach="docs" t-as="label">
@@ -23,47 +38,68 @@
                             <div class="page">
                                 <div class="oe_structure"/>
                                 <div class="row">
-                                      <table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse; margin: 0; padding: 0;">
-            												    <tr>
-            												        <td colspan="2" style="margin: 0; padding: 0;">
-            												            <h5 style="margin: 0; padding: 0;">
-            												                <span t-field="product.display_name"/>
-
-            												            </h5>
-            												        </td>
-            												    </tr>
-            												    <tr>
-            												        <!-- <td colspan="2" style="margin: 0; padding: 0;">
-            												            <h5 style="margin: 0; padding: 0;"><span>Precio: </span><span t-field="product.lst_price" /></h5>
-            												        </td> -->
-            												    </tr>
-            														<tr style="border: 1px solid black; margin: 0; padding: 0;">
-            															<td colspan="2" style="margin: 0; padding: 0;">
-            																	<span t-if="product.ean13">
-            																			<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="margin-top: 1px; width:70mm; height:13mm; margin: 0; padding: 0;"/>
-            																			<h5 style="margin: 0; padding: 0;"><span t-esc="product.ean13" /></h5>
-            																	</span>
-            															</td>
-            													</tr>
-
-                                        <!-- <tr style="border: 1px solid black;">
+                                    <table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse;">
+                                        <tr>
                                             <td colspan="2">
-                                                <h5><span t-field="line.product_id.name"/></h5>
+                                              <h5><span t-field="product.display_name"/>
+                                              </h5>
                                             </td>
                                         </tr>
-                                        <tr style="border: 1px solid black;">
+                                        <tr>
                                             <td colspan="2">
-                                                <h4><span>Precio: </span><span t-field="line.product_id.list_price" /></h4>
+                                                <span t-if="product.ean13">
+                                                    <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="width:70mm; height:13mm;"/>
+                                                    <h5><span t-esc="product.ean13"/></h5>
+                                                </span>
                                             </td>
                                         </tr>
-                                        <tr style="border: 1px solid black;">
+                                    </table>
+                                </div>
+                            </div>
+                        </t>
+                    </t>
+                </t>
+            </t>
+        </template>
+
+        <!-- New Template for Label with Price -->
+        <template id="product_product_label_with_price">
+            <t t-call="report.html_container">
+                <t t-foreach="docs" t-as="label">
+                    <t t-foreach="label.label_lines" t-as="line">
+                        <t t-foreach="range(int(line.quantity))" t-as="range_line">
+                            <div class="page">
+                                <div class="oe_structure"/>
+                                <div class="row">
+                                    <table style="width: 100%; border: 1px solid black; text-align: center; border-collapse: collapse;">
+                                      <tr>
+                                         <td colspan="2" style="margin: 0; padding: 0;">
+                                             <!-- Verificar que el producto exista antes de mostrar su nombre -->
+                                             <t t-if="product.display_name">
+                                                 <h5 style="margin: 0; padding: 0;">
+                                                     <span t-field="product.display_name"/>
+                                                 </h5>
+                                             </t>
+                                         </td>
+                                     </tr>
+                                     <tr>
+                                         <td colspan="2" style="margin: 0; padding: 0;">
+                                             <!-- Verificar que el producto y el precio existan antes de mostrar el precio -->
+                                             <t t-if="product and product.lst_price">
+                                                 <h5 style="margin: 0; padding: 0;">
+                                                     Precio: <span t-esc="product.lst_price"/>
+                                                 </h5>
+                                             </t>
+                                         </td>
+                                     </tr>
+                                        <tr>
                                             <td colspan="2">
-                                                <span t-if="line.product_id.ean13">
-                                                    <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', line.product_id.ean13, 400, 100)" style="margin-top: 3px; width:70mm; height:25mm"/>
-                                                    <h5><span t-esc="line.product_id.ean13" /></h5>
+                                                <span t-if="product.ean13">
+                                                    <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.ean13, 600, 13)" style="width:70mm; height:13mm;"/>
+                                                    <h5><span t-esc="product.ean13"/></h5>
                                                 </span>
                                             </td>
-                                        </tr> -->
+                                        </tr>
                                     </table>
                                 </div>
                             </div>
@@ -72,6 +108,5 @@
                 </t>
             </t>
         </template>
-
     </data>
 </openerp>

+ 7 - 5
views/product_product.xml

@@ -1,20 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
-
-        <record id="product_normal_form_view" model="ir.ui.view">
+        <!-- Vista heredada para product.product -->
+        <record id="product_product_form_view_inherit" model="ir.ui.view">
             <field name="name">ProductProductViewFormInherit</field>
             <field name="model">product.product</field>
-            <field name="inherit_id" ref="product.product_normal_form_view" />
+            <field name="inherit_id" ref="product.product_normal_form_view"/>
             <field eval="900" name="priority"/>
             <field name="arch" type="xml">
                 <xpath expr="//sheet" position="before">
                     <header>
+                        <!-- Botón para imprimir etiquetas sin precio -->
                         <button class="oe_highlight" type="object" string="Etiqueta" name="print_labels"/>
+                        <!-- Botón para imprimir etiquetas con precio -->
+                        <button class="oe_highlight" type="object" string="Etiqueta con Precio" name="print_labels_with_price"/>
                     </header>
                 </xpath>
             </field>
         </record>
-
     </data>
-</openerp>
+</openerp>

+ 2 - 1
views/product_template.xml

@@ -11,10 +11,11 @@
                 <xpath expr="//sheet" position="before">
                     <header>
                         <button class="oe_highlight" type="object" string="Etiqueta" name="print_labels"/>
+                        <button class="oe_highlight" type="object" string="Etiqueta con Precio" name="print_labels_with_price"/>
                     </header>
                 </xpath>
             </field>
         </record>
 
     </data>
-</openerp>
+</openerp>

+ 1 - 0
wizard/product_product_label_print.py

@@ -79,4 +79,5 @@ class ProductProductLabelLine(models.TransientModel):
             'name': self.product_id.name,
             'code': self.product_id.default_code or False,
             'barcode': self.product_id.ean13 or False,
+            'price': self.product_id.lst_price or 0.0,  # Agregando el precio del producto
         }

BIN
wizard/product_product_label_print.pyc


+ 4 - 0
wizard/product_product_label_print.xml

@@ -17,6 +17,10 @@
                     </group>
                     <footer>
                         <button string="Imprimir" name="print_labels" type="object" default_focus="1" class="btn-primary"/>
+
+                        <!-- Nuevo botón para imprimir etiquetas con precio -->
+                        <button string="Imprimir con Precio" name="print_labels_with_price" type="object" class="btn-secondary"/>
+
                         <button string="Cancelar" class="btn-default" special="cancel"/>
                     </footer>
                 </form>