Esempio n. 1
0
    def fields(self):
        # Only users with admin or purchase permission can modify transporters
        user = api.get_current_user(self.store)
        can_modify_transporter = any((
            user.profile.check_app_permission(u'admin'),
            user.profile.check_app_permission(u'purchase'),
        ))
        freight_types = [(v, k) for k, v in Delivery.freights.items()]
        states = [(v, v) for v in api.get_l10n_field('state').state_list]

        return collections.OrderedDict(
            recipient=PersonQueryField(_("Recipient"), proxy=True, mandatory=True,
                                       person_type=self.person_type),
            transporter_id=PersonField(_("Transporter"), proxy=True,
                                       person_type=Transporter,
                                       can_add=can_modify_transporter,
                                       can_edit=can_modify_transporter),
            address=AddressField(_("Address"), proxy=True, mandatory=True),
            freight_type=ChoiceField(_("Freight type"), proxy=True,
                                     values=freight_types),
            price=PriceField(_("Delivery cost"), proxy=True),
            estimated_fix_date=DateField(_("Estimated delivery date"), proxy=True),
            volumes_kind=TextField(_("Volumes kind"), proxy=True),
            volumes_quantity=IntegerField(_("Volumes quantity"), proxy=True),
            volumes_net_weight=NumericField(_("Volumes net weight"), proxy=True,
                                            digits=3),
            volumes_gross_weight=NumericField(_("Volumes gross weight"),
                                              proxy=True, digits=3),
            vehicle_license_plate=TextField(_("Vehicle license plate"), proxy=True),
            vehicle_state=ChoiceField(_("Vehicle state"), proxy=True, use_entry=True,
                                      values=states),
            vehicle_registration=TextField(_("Vehicle registration"), proxy=True),
        )
Esempio n. 2
0
 def fields(self):
     return collections.OrderedDict(
         code=TextField(_('Code'), proxy=True),
         description=TextField(_('Description'), proxy=True),
         barcode=TextField(_('Barcode'), proxy=True),
         price=PriceField(_('Price'), proxy=True),
         quantity=NumericField(_('Quantity'), proxy=True),
         skip=NumericField(_('Labels to skip'), proxy=True),
     )
Esempio n. 3
0
class InventoryItemAdjustmentEditor(BaseEditor):
    title = _(u"Product Adjustment")
    hide_footer = False
    size = (500, 300)
    model_type = InventoryItem

    fields = dict(
        description=TextField(_("Product"), proxy=True, editable=False),
        recorded_quantity=TextField(_("Previous quantity"),
                                    proxy=True,
                                    editable=False),
        counted_quantity=TextField(_("Counted quantity"),
                                   proxy=True,
                                   editable=False),
        difference=TextField(_("Difference"), proxy=True, editable=False),
        actual_quantity=NumericField(_("Actual quantity"),
                                     proxy=True,
                                     mandatory=True),
        cfop_data=CfopField(_("C.F.O.P"), proxy=True),
        reason=MultiLineField(_("Reason"), proxy=True, mandatory=True),
    )

    def __init__(self, store, model, invoice_number):
        BaseEditor.__init__(self, store, model)
        self._invoice_number = invoice_number

    #
    #  BaseEditor
    #

    def setup_proxies(self):
        self.actual_quantity.update(self.model.counted_quantity)

    def on_confirm(self):
        self.model.adjust(self._invoice_number)
Esempio n. 4
0
class _ItemEditor(BaseEditor):
    model_name = _(u'Work order item')
    model_type = _TempSaleItem
    confirm_widgets = ['price', 'quantity']

    fields = dict(
        price=PriceField(_(u'Price'), proxy=True, mandatory=True),
        quantity=NumericField(_(u'Quantity'), proxy=True, mandatory=True),
    )

    def on_confirm(self):
        self.model.update()

    def on_price__validate(self, widget, value):
        if value <= 0:
            return ValidationError(_(u"The price must be greater than 0"))

        sellable = self.model.sellable
        if not sellable.is_valid_price(value):
            return ValidationError(
                _(u"Max discount for this product "
                  u"is %.2f%%") % sellable.max_discount)

    def on_quantity__validate(self, entry, value):
        sellable = self.model.sellable

        # TODO: Validate quantity properly (checking if the current stock is
        # enougth
        if value <= 0:
            return ValidationError(_(u"The quantity must be greater than 0"))

        if not sellable.is_valid_quantity(value):
            return ValidationError(
                _(u"This product unit (%s) does not "
                  u"support fractions.") % sellable.get_unit_description())
Esempio n. 5
0
    def fields(self):
        # Only users with admin or purchase permission can modify transporters
        user = api.get_current_user(self.store)
        can_modify_transporter = any((
            user.profile.check_app_permission(u'admin'),
            user.profile.check_app_permission(u'purchase'),
        ))
        freight_types = [(v, k) for k, v in Delivery.freights.items()]
        states = [(v, v) for v in api.get_l10n_field('state').state_list]

        return collections.OrderedDict(
            recipient_str=TextField(_("Recipient"), proxy=True,
                                    editable=False),
            transporter_id=PersonField(_("Transporter"),
                                       proxy=True,
                                       person_type=Transporter,
                                       can_add=can_modify_transporter,
                                       can_edit=can_modify_transporter),
            address=AddressField(_("Address"), proxy=True, mandatory=True),
            is_sent_check=BoolField(_("Was sent to deliver?")),
            send_date=DateField(_("Send date"), mandatory=True, proxy=True),
            tracking_code=TextField(_("Tracking code"), proxy=True),
            freight_type=ChoiceField(_("Freight type"),
                                     proxy=True,
                                     values=freight_types),
            volumes_kind=TextField(_("Volumes kind"), proxy=True),
            volumes_quantity=IntegerField(_("Volumes quantity"), proxy=True),
            volumes_net_weight=NumericField(_("Volumes net weight"),
                                            proxy=True,
                                            digits=3),
            volumes_gross_weight=NumericField(_("Volumes gross weight"),
                                              proxy=True,
                                              digits=3),
            vehicle_license_plate=TextField(_("Vehicle license plate"),
                                            proxy=True),
            vehicle_state=ChoiceField(_("Vehicle state"),
                                      proxy=True,
                                      use_entry=True,
                                      values=states),
            vehicle_registration=TextField(_("Vehicle registration"),
                                           proxy=True),
            is_received_check=BoolField(_("Was received by recipient?")),
            receive_date=DateField(_("Receive date"),
                                   mandatory=True,
                                   proxy=True),
            empty=EmptyField(),
        )
Esempio n. 6
0
 def fields(self):
     return collections.OrderedDict(
         description=TextField(_("Product"), proxy=True, editable=False),
         recorded_quantity=TextField(_("Previous quantity"), proxy=True,
                                     editable=False),
         counted_quantity=TextField(_("Counted quantity"), proxy=True,
                                    editable=False),
         difference=TextField(_("Difference"), proxy=True, editable=False),
         actual_quantity=NumericField(_("Actual quantity"), proxy=True,
                                      mandatory=True),
         cfop_data=CfopField(_("C.F.O.P"), proxy=True),
         reason=MultiLineField(_("Reason"), proxy=True, mandatory=True),
     )
Esempio n. 7
0
class PrintLabelEditor(BaseEditor):
    """ This editor is used to gather information to print labels for a
    purchase item
    """
    model_type = object
    title = _(u'Print labels')

    fields = dict(
        code=TextField(_('Code'), proxy=True),
        description=TextField(_('Description'), proxy=True),
        barcode=TextField(_('Barcode'), proxy=True),
        price=PriceField(_('Price'), proxy=True),
        quantity=NumericField(_('Quantity'), proxy=True),
        skip=NumericField(_('Labels to skip'), proxy=True),
    )

    def __init__(self, store, sellable, model=None, max_quantity=None,
                 visual_mode=False):
        self.sellable = sellable
        self.max_quantity = max_quantity
        BaseEditor.__init__(self, store, model, visual_mode)
        self._setup_widgets()

    def _setup_widgets(self):
        for i in [self.code, self.description, self.barcode, self.price]:
            i.set_sensitive(False)
        if self.max_quantity:
            self.quantity.update(self.max_quantity)

    #
    # BaseEditor Hooks
    #

    def create_model(self, store):
        sellable = self.sellable
        return Settable(barcode=sellable.barcode, code=sellable.code,
                        description=sellable.description, price=sellable.price,
                        quantity=Decimal('1'), skip=Decimal('0'))
Esempio n. 8
0
class SkipLabelsEditor(BaseEditor):
    """ This dialog collects how many spaces should be skipped when printing a
    label
    """
    model_type = object
    title = _('Labels to skip')

    fields = dict(
        skip=NumericField(_('Labels to skip'), proxy=True),
    )

    def __init__(self, store):
        BaseEditor.__init__(self, store, None)

    def create_model(self, store):
        return Settable(skip=Decimal('0'))
Esempio n. 9
0
    def fields(self):
        # Check if sellable's unit allow fraction to use decimal places
        unit = self.model.product.sellable.unit
        if unit and unit.allow_fraction:
            quantity_digits = 3
        else:
            quantity_digits = 0

        return collections.OrderedDict(
            description=TextField(_("Product"), proxy=True, editable=False),
            recorded_quantity=TextField(_("Previous quantity"), proxy=True,
                                        editable=False),
            counted_quantity=TextField(_("Counted quantity"), proxy=True,
                                       editable=False),
            difference=TextField(_("Difference"), proxy=True, editable=False),
            actual_quantity=NumericField(_("Actual quantity"), proxy=True,
                                         mandatory=True, digits=quantity_digits),
            cfop_data=CfopField(_("C.F.O.P"), proxy=True),
            reason=MultiLineField(_("Reason"), proxy=True, mandatory=True),
        )
Esempio n. 10
0
class _WorkOrderItemEditor(BaseEditor):
    model_name = _(u'Work order item')
    model_type = WorkOrderItem
    confirm_widgets = ['price', 'quantity']

    fields = dict(
        price=PriceField(_(u'Price'), proxy=True, mandatory=True),
        quantity=NumericField(_(u'Quantity'), proxy=True, mandatory=True),
    )

    def on_price__validate(self, widget, value):
        if value <= 0:
            return ValidationError(_(u"The price must be greater than 0"))

        sellable = self.model.sellable
        # FIXME: Because of the design of the editor, the client
        # could not be set yet.
        category = self.model.order.client and self.model.order.client.category
        if not sellable.is_valid_price(value, category):
            return ValidationError(
                _(u"Max discount for this product "
                  u"is %.2f%%") % sellable.max_discount)

    def on_quantity__validate(self, entry, value):
        sellable = self.model.sellable
        storable = sellable.product_storable
        if not storable:
            return

        if value <= 0:
            return ValidationError(_(u"The quantity must be greater than 0"))

        if value > storable.get_balance_for_branch(self.model.order.branch):
            return ValidationError(
                _(u"This quantity is not available in stock"))

        if not sellable.is_valid_quantity(value):
            return ValidationError(
                _(u"This product unit (%s) does not "
                  u"support fractions.") % sellable.get_unit_description())
Esempio n. 11
0
    def fields(self):
        # Check if sellable's unit allow fraction to use decimal places
        unit = self._product.sellable.unit
        if unit and unit.allow_fraction:
            quantity_digits = 3
        else:
            quantity_digits = 0

        fields = collections.OrderedDict(
            quantity=NumericField(_('Quantity'),
                                  proxy=True,
                                  mandatory=True,
                                  digits=quantity_digits), )
        # When creating an inventory, a reason is necessary
        if self._stock_item:
            fields['reason'] = MultiLineField(_('Reason'),
                                              proxy=True,
                                              mandatory=True)
        else:
            # Inventories dont do anything with the cost yet. Maybe we should
            # fix that
            fields['cost'] = PriceField(_('Cost'), proxy=True, mandatory=True)
        return fields
Esempio n. 12
0
 def fields(self):
     return collections.OrderedDict(
         price=PriceField(_(u'Price'), proxy=True, mandatory=True),
         quantity=NumericField(_(u'Quantity'), proxy=True, mandatory=True),
         quantity_reserved=NumericField(_(u'Reserved quantity')),
     )
Esempio n. 13
0
 def fields(self):
     return collections.OrderedDict(skip=NumericField(_('Labels to skip'),
                                                      proxy=True), )
Esempio n. 14
0
class _WorkOrderItemEditor(BaseEditor):
    model_name = _(u'Work order item')
    model_type = WorkOrderItem
    confirm_widgets = ['price', 'quantity']

    fields = dict(
        price=PriceField(_(u'Price'), proxy=True, mandatory=True),
        quantity=NumericField(_(u'Quantity'), proxy=True, mandatory=True),
    )

    #: The manager is someone who can allow a bigger discount for a sale item.
    manager = None

    def __init__(self, *args, **kwargs):
        BaseEditor.__init__(self, *args, **kwargs)
        self.price.set_icon_activatable(gtk.ENTRY_ICON_PRIMARY,
                                        activatable=True)

    def on_price__validate(self, widget, value):
        if value <= 0:
            return ValidationError(_(u"The price must be greater than 0"))

        sellable = self.model.sellable
        self.manager = self.manager or api.get_current_user(self.store)

        # FIXME: Because of the design of the editor, the client
        # could not be set yet.
        category = self.model.order.client and self.model.order.client.category
        valid_data = sellable.is_valid_price(value, category, self.manager)
        if not valid_data['is_valid']:
            return ValidationError(
                _(u'Max discount for this product is %.2f%%.' %
                  valid_data['max_discount']))

    def on_price__icon_press(self, entry, icon_pos, event):
        if icon_pos != gtk.ENTRY_ICON_PRIMARY:
            return

        # Ask for the credentials of a different user that can possibly allow a
        # bigger discount.
        self.manager = run_dialog(CredentialsDialog, self, self.store)
        if self.manager:
            self.price.validate(force=True)

    def on_quantity__validate(self, entry, value):
        sellable = self.model.sellable

        if value <= 0:
            return ValidationError(_(u"The quantity must be greater than 0"))

        if not sellable.is_valid_quantity(value):
            return ValidationError(
                _(u"This product unit (%s) does not "
                  u"support fractions.") % sellable.get_unit_description())

        try:
            remaining_quantity = self.model.get_remaining_quantity()
        except StockError:
            # No need to validate the quantity, the item doesn't have a storable
            return

        if value > self.model.quantity + remaining_quantity:
            return ValidationError(
                _(u"This quantity is not available in stock"))