Changeset 25684be in rattail


Ignore:
Timestamp:
03/11/19 19:31:29 (4 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
8a0d62f
Parents:
fb5d695
Message:

Add BatchHandler.do_remove_row() caller method

also delete row outright, when removing row from purchase batch

Location:
rattail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/handlers.py

    rfb5d695 r25684be  
    432432    def remove_row(self, row):
    433433        """
    434         Remove the given row from its batch.  This may delete the row outright
    435         from the database, or simply mark it as removed etc.  Defaults to the
    436         latter.
    437         """
    438         if row.removed:
    439             return
     434        Remove the given row from its batch, and update the batch accordingly.
     435        How exactly the row is "removed" is up to this method.  Default is to
     436        set the row's :attr:`~rattail.db.model.batch.BatchRowMixin.removed`
     437        flag, then invoke the :meth:`~refresh_batch_status()` method.
     438
     439        Execute the given batch, with given progress and kwargs.  That is an
     440        intentionally generic statement, the meaning of which must be further
     441        defined by the handler subclass since default is ``NotImplementedError``.
     442
     443        Note that callers should *not* use this method, but custom batch
     444        handlers *should* override this method.  Conversely, custom handlers
     445        should *not* override the :meth:`~do_remove_row()` method, but callers
     446        *should* use that one directly.
     447        """
    440448        batch = row.batch
    441449        row.removed = True
    442450        self.refresh_batch_status(batch)
     451
     452    def do_remove_row(self, row):
     453        """
     454        Remove the given row from its batch, and update the batch accordingly.
     455
     456        Note that callers *should* use this method, but custom batch handlers
     457        should *not* override this method.  Conversely, custom handlers
     458        *should* override the :meth:`~remove_row()` method, but callers should
     459        *not* use that one directly.
     460        """
     461        if row.removed:
     462            return
     463        self.remove_row(row)
     464        batch = row.batch
    443465        if batch.rowcount is not None:
    444466            batch.rowcount -= 1
  • rattail/batch/purchase.py

    rfb5d695 r25684be  
    15831583    def remove_row(self, row):
    15841584        """
    1585         When removing a row from purchase batch, (maybe) must also update some
    1586         totals for the batch.
    1587         """
     1585        This handler does not simply mark the row "removed" but will instead
     1586        delete the row outright.  It additionally will update certain (PO,
     1587        invoice) totals on the batch.
     1588        """
     1589        session = orm.object_session(row)
    15881590        batch = row.batch
    15891591
     
    15921594                batch.po_total -= row.po_total
    15931595
    1594         if batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING:
     1596        elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING:
    15951597            if row.invoice_total_calculated:
    15961598                batch.invoice_total_calculated -= row.invoice_total_calculated
    15971599
    1598         super(PurchaseBatchHandler, self).remove_row(row)
     1600        session.delete(row)
     1601        session.flush()
     1602        self.refresh_batch_status(batch)
    15991603
    16001604    def get_unit_cost(self, product, vendor):
  • rattail/db/model/batch/purchase.py

    rfb5d695 r25684be  
    363363        backref=orm.backref(
    364364            'credits',
     365            cascade='all, delete-orphan',
    365366            doc="""
    366367            List of :class:`PurchaseBatchCredit` instances for the row.
Note: See TracChangeset for help on using the changeset viewer.