Explorar el Código

Añadir campo medic_id en account_invoice_line

sebastian hace 5 años
padre
commit
1d5b4fbe7e

+ 1 - 1
models/__init__.py

@@ -1 +1 @@
-import sale_order
+import sale_order, account_invoice

BIN
models/__init__.pyc


+ 14 - 0
models/account_invoice.py

@@ -0,0 +1,14 @@
+# -*- encoding: utf-8 -*-
+
+from openerp import models, api, fields
+
+class aa_invoice_custom_lines(models.Model):
+    _inherit = 'account.invoice.line'
+    medic_id = fields.Many2one('res.partner',"Médico", domain="[('is_medic', '=', True)]")
+
+    # def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
+    #     ret = super(aa_invoice_custom_lines, self)._prepare_order_line_invoice_line(cr, uid, line, account_id=False, context=context)
+    #     if line.product_id:
+    #         if line.medic_id:
+    #             ret['medic_id'] = line.medic_id
+    #     return ret

BIN
models/account_invoice.pyc


+ 58 - 1
models/sale_order.py

@@ -2,6 +2,63 @@
 
 from openerp import models, api, fields
 
+
 class NewSaleOrderLine(models.Model):
     _inherit = 'sale.order.line'
-    employee_id = fields.Many2one('res.partner', "Médico", domain="[('is_medic', '=', True)]")
+
+    medic_id = fields.Many2one('res.partner', "Médico", domain="[('is_medic', '=', True)]")
+
+    def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
+        """Prepare the dict of values to create the new invoice line for a
+           sales order line. This method may be overridden to implement custom
+           invoice generation (making sure to call super() to establish
+           a clean extension chain).
+
+           :param browse_record line: sale.order.line record to invoice
+           :param int account_id: optional ID of a G/L account to force
+               (this is used for returning products including service)
+           :return: dict of values to create() the invoice line
+        """
+        res = {}
+        if not line.invoiced:
+            if not account_id:
+                if line.product_id:
+                    account_id = line.product_id.property_account_income.id
+                    if not account_id:
+                        account_id = line.product_id.categ_id.property_account_income_categ.id
+                    if not account_id:
+                        raise osv.except_osv(_('Error!'),
+                                _('Please define income account for this product: "%s" (id:%d).') % \
+                                    (line.product_id.name, line.product_id.id,))
+                else:
+                    prop = self.pool.get('ir.property').get(cr, uid,
+                            'property_account_income_categ', 'product.category',
+                            context=context)
+                    account_id = prop and prop.id or False
+            uosqty = self._get_line_qty(cr, uid, line, context=context)
+            uos_id = self._get_line_uom(cr, uid, line, context=context)
+            pu = 0.0
+            if uosqty:
+                pu = round(line.price_unit * line.product_uom_qty / uosqty,
+                        self.pool.get('decimal.precision').precision_get(cr, uid, 'Product Price'))
+            fpos = line.order_id.fiscal_position or False
+            account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, account_id)
+            if not account_id:
+                raise osv.except_osv(_('Error!'),
+                            _('There is no Fiscal Position defined or Income category account defined for default properties of Product categories.'))
+            res = {
+                'medic_id': line.medic_id.id or False,
+                'name': line.name,
+                'sequence': line.sequence,
+                'origin': line.order_id.name,
+                'account_id': account_id,
+                'price_unit': pu,
+                'quantity': uosqty,
+                'discount': line.discount,
+                'uos_id': uos_id,
+                'product_id': line.product_id.id or False,
+                'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],
+                'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,
+            }
+
+        return res

BIN
models/sale_order.pyc


+ 13 - 1
views/sale_order_view.xml

@@ -11,7 +11,19 @@
                 </xpath> -->
 
                 <xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
-                    <field name="employee_id" attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"/>
+                    <field name="medic_id" attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"/>
+                </xpath>
+            </field>
+        </record>
+
+
+        <record id="account.invoice_form_inherit3" model="ir.ui.view">
+            <field name="name">account.invoice.form.inherit3</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//tree[@string='Invoice Lines']/field[@name='name']" position="before">
+                    <field name="medic_id"/>
                 </xpath>
             </field>
         </record>