Prechádzať zdrojové kódy

[FIX-ADD] limpieza de codigo y se agrego la opcion de incluir o no materiales utilizados en la factura

Rodney Enciso Arias 7 rokov pred
rodič
commit
f370f452b8

+ 15 - 20
models/car_workshop.py

@@ -70,7 +70,8 @@ class CarWorkshop(models.Model):
     remaining_hour = fields.Float(string='Remaining Hour',readonly=True, compute="hours_left")
     effective_hour = fields.Float(string='Hours Spent', readonly=True, compute="hours_spent")
     amount_total = fields.Float(string='Total Amount', readonly=True, compute="amount_total1")
-
+    include_materials = fields.Boolean('Incluir')
+    
     _defaults = {
         'stage_id': 1,
         'vehicle_id': lambda self, cr, uid, ctx=None: ctx.get('default_vehicle_id') if ctx is not None else False,
@@ -91,8 +92,9 @@ class CarWorkshop(models.Model):
                 amount_totall = 0.0
                 for line in hour.planned_works:
                     amount_totall += line.work_cost
-                for line2 in hour.materials_used:
-                    amount_totall += line2.price
+                if self.include_materials==True:
+                    for line2 in hour.materials_used:
+                        amount_totall += line2.price
                 records.amount_total = amount_totall
 
     @api.multi
@@ -101,14 +103,12 @@ class CarWorkshop(models.Model):
 
     @api.multi
     def workshop_create_invoices(self):
-
         self.state = 'workshop_create_invoices'
         inv_obj = self.env['account.invoice']
         inv_line_obj = self.env['account.invoice.line']
         customer = self.partner_id
         if not customer.name:
             raise osv.except_osv(_('UserError!'), _('Please select a Customer.'))
-
         company_id = self.env['res.users'].browse(1).company_id
         currency_value = company_id.currency_id.id
         self.ensure_one()
@@ -142,29 +142,26 @@ class CarWorkshop(models.Model):
                 'invoice_id': inv_id.id,
             }
             inv_line_obj.create(inv_line_data)
-
         for records in self.materials_used:
             if records.material.id:
                 income_account = records.material.property_account_income.id
             if not income_account:
                 raise osv.except_osv(_('UserError!'), _('There is no income account defined '
                                                         'for this product: "%s".') % (records.material.name,))
-
-            inv_line_data = {
-                'name': records.material.name,
-                'account_id': records.material.property_account_income.id,
-                'price_unit': records.price,
-                'quantity': records.amount,
-                'product_id': records.material.id,
-                'invoice_id': inv_id.id,
-            }
-            inv_line_obj.create(inv_line_data)
-
+            if self.include_materials==True:
+                inv_line_data = {
+                    'name': records.material.name,
+                    'account_id': records.material.property_account_income.id,
+                    'price_unit': records.price,
+                    'quantity': records.amount,
+                    'product_id': records.material.id,
+                    'invoice_id': inv_id.id,
+                }
+                inv_line_obj.create(inv_line_data)
         imd = self.env['ir.model.data']
         action = imd.xmlid_to_object('account.action_invoice_tree1')
         list_view_id = imd.xmlid_to_res_id('account.invoice_tree')
         form_view_id = imd.xmlid_to_res_id('account.invoice_form')
-
         result = {
             'name': action.name,
             'help': action.help,
@@ -183,7 +180,6 @@ class CarWorkshop(models.Model):
         else:
             result = {'type': 'ir.actions.act_window_close'}
         invoiced_records = self.env['car.workshop']
-
         total = 0
         for rows in invoiced_records:
             invoiced_date = rows.date
@@ -283,7 +279,6 @@ class CarWorkshop(models.Model):
             vehicle = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context)
             if vehicle.exists():
                 values['partner_id'] = vehicle.partner_id.id
-                # values['stage_id'] = self.find_stage(cr, uid, [], vehicle_id, [('fold', '=', False)], context=context)
         else:
             values['stage_id'] = False
         return {'value': values}

BIN
models/car_workshop.pyc


+ 1 - 1
models/timesheet.py

@@ -45,7 +45,7 @@ class MaterialUsed (models.Model):
     _name = 'material.used'
 
     material = fields.Many2one('product.template', string='Productos', domain=[('sale_ok','=',True)])
-    amount = fields.Integer(string='Cantidad')
+    amount = fields.Integer(string='Cantidad', default=1)
     price = fields.Float(string='Precio Unitario')
     material_id = fields.Many2one(string='car.workshop')
 

BIN
models/timesheet.pyc


+ 2 - 2
static/src/css/vehicles.css

@@ -6,5 +6,5 @@
     height: 191px;
 }
 .card-image-box > img{
-	width: 70% !important;
-}
+    width: 70% !important;
+}

+ 9 - 3
views/worksheet_views.xml

@@ -32,10 +32,10 @@
                             </group>
                         </group>
                         <notebook>
-                            <page name="description_page" string="Descripción">
+                            <!--<page name="description_page" string="Descripción">
                                 <field name="description" type="html"/>
                                 <div class="oe_clear"/>
-                            </page>
+                            </page>-->
                             <page name="timesheet_page" string="Hoja de trabajo">
                                 <group string ="Trabajo Planeado">
                                     <field name="planned_works" nolabel="1" attrs="{'readonly': [('state','!=', 'waiting')]}">
@@ -64,7 +64,13 @@
                                     <field name="materials_used" nolabel="1" attrs="{'readonly': [('state','=', 'workshop_create_invoices')]}"/>
                                 </group>
                                 <group>
-                                    <field name="amount_total" string="Monto Total"/>
+                                    <field name="include_materials" class="oe_inline" string="¿Incluir materiales en la factura?" attrs="{'readonly': [('state','=', 'workshop_create_invoices')]}"/>
+                                </group>
+                                <group>
+                                    <label for="amount_total" string="Monto Total"/>
+                                    <h1>
+                                        <field name="amount_total"/>
+                                    </h1>
                                 </group>
                                  <group class="oe_subtotal_footer oe_right" name="project_hours">
                                       <field name="effective_hour" widget="float_time" string="Horas Gastadas"/>