12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # -*- encoding: utf-8 -*-
- from openerp import models, api, fields
- class NewSaleOrderLine(models.Model):
- _inherit = 'sale.order.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):
- """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
|