Пример #1
0
    def unlink(self):
        for invoice in self:
            if invoice.state not in ('draft', 'cancel', 'paid'):
                raise models.UserError(
                    _('You cannot delete an invoice which is not draft or cancelled. You should create a credit note instead.'
                      ))
            elif invoice.move_name:
                raise models.UserError(
                    _('You cannot delete an invoice after it has been validated (and received a number). You can set it back to "Draft" state and modify its content, then re-confirm it.'
                      ))

            for lease in invoice.lease_ids:
                the_invoice = self.env['account.invoice'].search(
                    [('id', 'in', lease.invoice_ids.ids),
                     ('state', '!=', 'cancel'), ('id', '!=', invoice.id)],
                    limit=1,
                    order='date_invoice desc')

                if the_invoice:
                    lease.last_invoice_date = invoice.date_invoice
                else:
                    lease.last_invoice_date = False

                lease.message_post(
                    body='<p><b>Invoice Deleted:</b></p><p>Invoice dated: ' +
                    str(invoice.invoice_posting_date) + ' for: $' +
                    str(invoice.amount_total_signed) +
                    ' for this lease was deleted</p>',
                    subject="Invoice Deleted",
                    subtype="mt_note")

        return super(ThomasAccountingInvoice, self).unlink()
Пример #2
0
    def write(self, vals):
        """重写 检查文章数量"""
        article_ids = vals.get('article_ids')
        if len(article_ids[0][2]) > 8:
            raise models.UserError(u'图文回复文章数量最多为8篇!')

        return super(ArticlesReply, self).write(vals)
Пример #3
0
 def get_dte(self):
     company_id = self.env.user.company_id
     url = company_id.dte_url
     rut_company = company_id.invoice_rut.replace(".", "").split("-")[0]
     fecha_desde = '2020-01-01'
     fecha_hasta = date.today()
     apidte = '/dte/dte_recibidos/buscar/{}?fecha_desde={}&fecha_hasta={}'.format(rut_company, fecha_desde,
                                                                                  fecha_hasta)
     hash = company_id.dte_hash
     auth = requests.auth.HTTPBasicAuth(hash, 'X')
     dtes = requests.get(url + '/api' + apidte, auth=auth)
     if dtes.status_code != 200:
         raise models.UserError('Error al Temporal: ' + dtes.json())
     data = dtes.json()
     if len(data) != 0:
         for d in data:
             invoice = self.env['custom.invoice'].search([('invoice', '=', d.get('folio', None))])
             if invoice:
                 continue
             partner_id = self.env['res.partner'].search([('invoice_rut', '=', d.get('rut_f').strip())])
             dte_type = self.env['dte.type'].search([('code', '=', d.get('dte', None))])
             if partner_id:
                 self.env['custom.invoice'].create({
                     'date': d.get('fecha', None),
                     'transmitter': d.get('emisor', None),
                     'partner_id': partner_id.id,
                     'dte': dte_type.id,
                     'business_name': d.get('razon_social', None),
                     'invoice': d.get('folio', None),
                     'branch_office': d.get('sucursal', None),
                     'exempt': False,
                     'net_value': d.get('neto', None),
                     'total_value': d.get('total', None),
                     'dv': d.get('dv', None),
                     'rut_f': d.get('rut_f', None),
                     'giro': d.get('giro', None),
                 })
             else:
                 self.env['custom.invoice'].create({
                     'date': d.get('fecha', None),
                     'transmitter': d.get('emisor', None),
                     'partner_id': None,
                     'dte': dte_type.id,
                     'business_name': d.get('razon_social', None),
                     'invoice': d.get('folio', None),
                     'branch_office': d.get('sucursal', None),
                     'exempt': False,
                     'net_value': d.get('neto', None),
                     'total_value': d.get('total', None),
                     'dv': d.get('dv', None),
                     'rut_f': d.get('rut_f', None),
                     'giro': d.get('giro', None),
                 })
     return {
         'type': 'ir.actions.client',
         'tag': 'reload',
     }
Пример #4
0
 def unlink(self):
     """
     控制单据的删除,只能删除草稿状态的单据
     :return: 
     """
     for order in self:
         if not order.state == 'draft':
             raise models.UserError(u'无法删除非草稿状态的单据')
         order.employee_id.unlink()
     return super(Entry, self).unlink()
Пример #5
0
 def cambiar_estado(self, estado_novo):
     for equipo in self:
         if equipo.estado != estado_novo:
             if equipo.cambios_estado_permitidos(equipo.estado,
                                                 estado_novo):
                 equipo.estado = estado_novo
             else:
                 mensaxe = ('Non se pode cambiar de <%s> a <%s>') % (
                     equipo.estado, estado_novo)
                 raise models.UserError(mensaxe)
Пример #6
0
 def unlink_selecction(self):
     for item in self:
         if not item.serial_without_pallet_ids.filtered(
                 lambda a: a.to_unlink):
             raise models.UserError("No ha seleccionado nada")
         else:
             if item.serial_without_pallet_ids.filtered(
                     lambda a: a.consumed):
                 raise models.ValidationError(
                     'Existe una o mas series consumidas')
             else:
                 item.serial_without_pallet_ids.filtered(
                     lambda a: a.to_unlink).sudo().unlink()
Пример #7
0
 def inmediate_transfer(self, picking):
     pick_to_backorder = self.env['stock.picking']
     pick_to_do = self.env['stock.picking']
     if picking.state == 'draft':
         picking.action_confirm()
         if picking.state != 'assigned':
             picking.action_assign()
             if picking.state != 'assigned':
                 raise models.ValidationError("Prueba 123")
                 raise models.UserError((
                     "Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually."
                 ))
     for move in picking.move_lines.filtered(
             lambda m: m.state not in ['done', 'cancel']):
         for move_line in move.move_line_ids:
             move_line.qty_done = move_line.product_uom_qty
     if self.check_backorder(picking):
         pick_to_backorder |= picking
     pick_to_do |= picking
Пример #8
0
 def process_serial(self, serial_number):
     lots = self.potential_serial_planned_ids
     weigths = lots.mapped('display_weight')
     if not isinstance(self.id, int):
         self = self._origin
     serial_number = serial_number.strip()
     serial = self.env['stock.production.lot.serial'].search([
         ('serial_number', '=', serial_number),
         ('stock_production_lot_id', '!=', False)
     ])
     if not serial:
         raise models.ValidationError(f'La serie ingresada no existe')
     if serial.product_id not in self.material_product_ids:
         raise models.UserError(
             f'El producto de la serie {serial.serial_number} no es compatible con la lista de materiales'
         )
     if serial.consumed:
         raise models.UserError(
             f'El serie se encuentra consumida en el proceso {serial.reserved_to_production_id.name}'
         )
     self.component_id = serial.product_id
     self.write({'lot_id': serial.stock_production_lot_id.id})
     serial.write({
         'reserved_to_production_id': self.production_id.id,
         'consumed': True,
         'used_in_workorder_id': self.id
     })
     if serial.producer_id not in self.producers_id:
         self.write({'producers_id': [(4, serial.producer_id.id)]})
     serial.stock_production_lot_id.update_stock_quant_production(
         self.production_id.location_src_id.id)
     serial.stock_production_lot_id.update_kg(
         serial.stock_production_lot_id.id)
     line_new = self.env['stock.move.line']
     move = self.production_id.move_raw_ids.filtered(
         lambda a: a.product_id.id == serial.product_id.id)
     if move.active_move_line_ids:
         line = move.active_move_line_ids.filtered(
             lambda a: a.lot_id == serial.stock_production_lot_id)
         if not line.lot_produced_id:
             line.write({'lot_produced_id': self.final_lot_id.id})
         line.write({
             'qty_done':
             sum(
                 self.potential_serial_planned_ids.filtered(
                     lambda a: a.stock_production_lot_id.id == serial.
                     stock_production_lot_id.id).mapped('display_weight'))
         })
     else:
         line_new = self.env['stock.move.line'].create({
             'lot_id':
             serial.stock_production_lot_id.id,
             'lot_produced_id':
             self.final_lot_id.id,
             'product_id':
             move.product_id.id,
             'location_dest_id':
             self.env['stock.location'].search([('usage', '=', 'production')
                                                ]).id,
             'location_id':
             self.production_id.location_src_id.id,
             'move_id':
             move.id,
             'product_uom_id':
             serial.product_id.uom_id.id,
             'date':
             date.today(),
             'qty_done':
             sum(
                 self.potential_serial_planned_ids.filtered(
                     lambda a: a.stock_production_lot_id.id == serial.
                     stock_production_lot_id.id).mapped('display_weight')),
             'production_id':
             self.production_id.id,
             'workorder_id':
             self.id,
             'is_raw':
             True
         })
     if self.active_move_line_ids.filtered(
             lambda a: not a.lot_id and a.product_id.id == serial.product_id
             .id):
         line_wo = self.active_move_line_ids.filtered(
             lambda a: not a.lot_id and a.product_id.id == serial.product_id
             .id)
         line_wo.write({
             'lot_id':
             serial.stock_production_lot_id.id,
             'qty_done':
             sum(
                 self.potential_serial_planned_ids.filtered(
                     lambda a: a.stock_production_lot_id.id == serial.
                     stock_production_lot_id.id).mapped('display_weight'))
         })
     else:
         line_wo = self.active_move_line_ids.filtered(
             lambda a: a.lot_id.id == serial.stock_production_lot_id.id and
             a.product_id.id == serial.product_id.id)
         if line_wo:
             line_wo.write({
                 'qty_done':
                 sum(
                     self.potential_serial_planned_ids.filtered(
                         lambda a: a.stock_production_lot_id.id == serial.
                         stock_production_lot_id.id).mapped(
                             'display_weight'))
             })
         else:
             self.env['stock.move.line'].create({
                 'lot_id':
                 serial.stock_production_lot_id.id,
                 'lot_produced_id':
                 self.final_lot_id.id,
                 'product_id':
                 move.product_id.id,
                 'location_dest_id':
                 self.env['stock.location'].search([('usage', '=',
                                                     'production')]).id,
                 'location_id':
                 self.production_id.location_src_id.id,
                 'move_id':
                 self.move_raw_ids.filtered(
                     lambda a: a.product_id.id == serial.product_id.id).id,
                 'product_uom_id':
                 serial.product_id.uom_id.id,
                 'date':
                 date.today(),
                 'qty_done':
                 sum(
                     self.potential_serial_planned_ids.filtered(
                         lambda a: a.stock_production_lot_id.id == serial.
                         stock_production_lot_id.id).mapped(
                             'display_weight')),
                 'production_id':
                 self.production_id.id,
                 'workorder_id':
                 self.id,
                 'done_wo':
                 False,
                 'is_raw':
                 True
             })
     check = self.check_ids.filtered(
         lambda a: a.component_id.id == serial.product_id.id and not a.
         component_is_byproduct)
     check.write({
         'lot_id':
         serial.stock_production_lot_id.id,
         'move_line_id':
         line_new.id if line_new.id else line.id,
         'qty_done':
         sum(
             self.potential_serial_planned_ids.filtered(
                 lambda a: a.product_id.id == serial.product_id.id).mapped(
                     'display_weight'))
     })
     if check.quality_state != 'pass':
         check.do_pass()
     self.write({
         'confirmed_serial':
         None,
         'current_quality_check_id':
         check.id,
         'in_weight':
         sum(self.potential_serial_planned_ids.mapped('display_weight'))
     })