Example #1
0
def _customize_taskline_fields(schema):
    """
    Customize TaskLine colander schema related fields

    :param obj schema: The schema to modify
    """
    schema.validator = tva_product_validator
    customize = functools.partial(forms.customize_field, schema)
    customize('id', widget=deform.widget.HiddenWidget())
    customize(
        "description",
        widget=deform.widget.TextAreaWidget(),
        validator=forms.textarea_node_validator,
        preparer=clean_html
    )
    customize("cost", typ=AmountType(5), missing=colander.required)
    customize("quantity", typ=QuantityType(), missing=colander.required)
    customize(
        "unity",
        validator=forms.get_deferred_select_validator(WorkUnit, id_key='label'),
        missing=colander.drop,
    )
    customize(
        "tva",
        typ=AmountType(2),
        validator=forms.get_deferred_select_validator(Tva, id_key='value'),
        missing=colander.required,
    )
    customize(
        "product_id",
        validator=forms.get_deferred_select_validator(Product),
        missing=colander.drop,
    )
    return schema
Example #2
0
def _customize_payment_schema(schema):
    """
    Add form schema customization to the given payment edition schema

    :param obj schema: The schema to edit
    """
    customize = functools.partial(forms.customize_field, schema)
    customize(
        "mode",
        validator=forms.get_deferred_select_validator(
            PaymentMode, id_key='label'
        ),
        missing=colander.required
    )
    customize("amount", typ=AmountType(5), missing=colander.required)
    customize("bank_remittance_id", missing=colander.required)
    customize("date", missing=colander.required)
    customize("task_id", missing=colander.required)
    customize(
        "bank_id",
        validator=forms.get_deferred_select_validator(BankAccount),
        missing=colander.required,
    )
    customize(
        "tva_id",
        validator=forms.get_deferred_select_validator(Tva),
        missing=colander.drop,
    )
    customize("user_id", missing=colander.required)
    return schema
Example #3
0
def get_list_schema():
    """
    Return a list schema for user datas
    """
    schema = BaseListsSchema().clone()

    schema['search'].description = u"Nom, prénom, entreprise"

    schema.insert(0, colander.SchemaNode(
        colander.Integer(),
        name='situation_situation',
        widget=get_deferred_select(
            CaeSituationOption, empty_filter_msg=u"Tous les status"
        ),
        validator=get_deferred_select_validator(CaeSituationOption),
        missing=colander.drop,
    ))

    schema.insert(0, conseiller_filter_node_factory(
        name='situation_follower_id'
    ))

    antenne_filter_node = colander.SchemaNode(
        colander.Integer(),
        name="situation_antenne_id",
        widget=get_deferred_select(
            AntenneOption, empty_filter_msg=u"Toutes les antennes"
        ),
        validator=get_deferred_select_validator(AntenneOption),
        missing=colander.drop
    )
    schema.insert(0, antenne_filter_node)

    return schema
Example #4
0
def get_add_edit_line_schema(factory):
    """
    Build a schema for expense line

    :param class model: The model for which we want to generate the schema
    :rerturns: A SQLAlchemySchemaNode schema
    """
    excludes = ('sheet_id',)
    schema = SQLAlchemySchemaNode(factory, excludes=excludes)

    if factory == ExpenseLine:
        forms.customize_field(
            schema,
            'type_id',
            validator=forms.get_deferred_select_validator(
                ExpenseType,
                filters=[('type', 'expense')]
            ),
            missing=colander.required,
        )
    elif factory == ExpenseKmLine:
        forms.customize_field(
            schema,
            'type_id',
            validator=forms.get_deferred_select_validator(
                ExpenseKmType,
                filters=[('year', datetime.date.today().year)]
            ),
            missing=colander.required,
        )

    forms.customize_field(
        schema,
        'ht',
        typ=AmountType(2),
        missing=colander.required,
    )
    forms.customize_field(
        schema,
        'tva',
        typ=AmountType(2),
        missing=colander.required,
    )
    forms.customize_field(
        schema,
        'km',
        typ=AmountType(2),
        missing=colander.required,
    )
    return schema
Example #5
0
def _customize_discountline_fields(schema):
    """
    Customize DiscountLine colander schema related fields

    :param obj schema: The schema to modify
    """
    customize = functools.partial(forms.customize_field, schema)
    customize("id", widget=deform.widget.HiddenWidget())
    customize("task_id", missing=colander.required)
    customize(
        "description",
        widget=deform.widget.TextAreaWidget(),
        validator=forms.textarea_node_validator,
        preparer=clean_html
    )
    customize(
        "amount",
        typ=AmountType(5),
        missing=colander.required,
    )
    customize(
        "tva",
        typ=AmountType(2),
        validator=forms.get_deferred_select_validator(Tva, id_key='value'),
        missing=colander.required,
    )

    return schema
Example #6
0
def _customize_discountline_fields(schema):
    """
    Customize DiscountLine colander schema related fields

    :param obj schema: The schema to modify
    """
    customize = functools.partial(forms.customize_field, schema)
    customize("id", widget=deform.widget.HiddenWidget())
    customize("task_id", missing=colander.required)
    customize("description",
              widget=deform.widget.TextAreaWidget(),
              validator=forms.textarea_node_validator,
              preparer=clean_html)
    customize(
        "amount",
        typ=AmountType(5),
        missing=colander.required,
    )
    customize(
        "tva",
        typ=AmountType(2),
        validator=forms.get_deferred_select_validator(Tva, id_key='value'),
        missing=colander.required,
    )

    return schema
Example #7
0
class Payment(DBBASE, PersistentACLMixin):
    """
        Payment entry
    """
    __tablename__ = 'payment'
    __table_args__ = default_table_args
    id = Column(Integer, primary_key=True)
    created_at = Column(
        DateTime(),
        info={'colanderalchemy': {
            'exclude': True,
            'title': u"Créé(e) le",
        }},
        default=datetime.datetime.now,
    )

    updated_at = Column(DateTime(),
                        info={
                            'colanderalchemy': {
                                'exclude': True,
                                'title': u"Mis(e) à jour le",
                            }
                        },
                        default=datetime.datetime.now,
                        onupdate=datetime.datetime.now)

    mode = Column(String(50),
                  info={
                      'colanderalchemy': {
                          'title':
                          u"Mode de paiement",
                          'validator':
                          forms.get_deferred_select_validator(PaymentMode,
                                                              id_key='label'),
                          'missing':
                          colander.required,
                      }
                  })
    amount = Column(
        BigInteger(),
        info={
            'colanderalchemy': {
                "title": u"Montant",
                'missing': colander.required,
                "typ": AmountType(5)
            }
        },
    )
    remittance_amount = Column(
        String(255),
        info={
            'colanderalchemy': {
                'title': u"Identifiant de remise en banque",
                'missing': colander.required,
            }
        },
    )
    date = Column(
        DateTime(),
        info={
            'colanderalchemy': {
                'title': u"Date de remise",
                'missing': colander.required,
            }
        },
        default=datetime.datetime.now,
    )
    exported = Column(Boolean(), default=False)
    task_id = Column(Integer,
                     ForeignKey('task.id', ondelete="cascade"),
                     info={
                         'colanderalchemy': {
                             'title': u"Identifiant du document",
                             'missing': colander.required,
                         }
                     })
    bank_id = Column(ForeignKey('bank_account.id'),
                     info={
                         'colanderalchemy': {
                             'title':
                             u"Compte en banque",
                             'missing':
                             colander.required,
                             'validator':
                             forms.get_deferred_select_validator(BankAccount),
                         }
                     })
    tva_id = Column(ForeignKey('tva.id'),
                    info={
                        'colanderalchemy': {
                            'title': u"Tva associée à ce paiement",
                            'validator':
                            forms.get_deferred_select_validator(Tva),
                            'missing': colander.drop,
                        }
                    },
                    nullable=True)

    user_id = Column(
        ForeignKey('accounts.id'),
        info={
            'colanderalchemy': {
                'title': u"Utilisateur",
                'missing': colander.required,
            }
        },
    )

    user = relationship(
        "User",
        info={'colanderalchemy': {
            'exclude': True
        }},
    )

    bank = relationship("BankAccount",
                        back_populates='payments',
                        info={'colanderalchemy': {
                            'exclude': True
                        }})
    tva = relationship("Tva", info={'colanderalchemy': {'exclude': True}})
    task = relationship(
        "Task",
        primaryjoin="Task.id==Payment.task_id",
    )
    # Formatting precision
    precision = 5

    # Usefull aliases
    @property
    def invoice(self):
        return self.task

    @property
    def parent(self):
        return self.task

    # Simple function
    def get_amount(self):
        return self.amount

    def __unicode__(self):
        return u"<Payment id:{s.id} task_id:{s.task_id} amount:{s.amount}\
 mode:{s.mode} date:{s.date}".format(s=self)
Example #8
0
class DiscountLine(DBBASE, DiscountLineCompute):
    """
         A discount line
    """
    __tablename__ = 'discount'
    __table_args__ = default_table_args
    id = Column(
        Integer,
        primary_key=True,
        nullable=False,
        info={'colanderalchemy': {
            'widget': deform.widget.HiddenWidget()
        }})
    task_id = Column(Integer,
                     ForeignKey(
                         'task.id',
                         ondelete="cascade",
                     ),
                     info={
                         'colanderalchemy': {
                             'title': u"Identifiant du document",
                             'missing': colander.required,
                         }
                     })
    description = Column(Text,
                         info={
                             'colanderalchemy': {
                                 'widget': deform.widget.TextAreaWidget(),
                                 'validator': forms.textarea_node_validator,
                             }
                         })
    amount = Column(
        BigInteger(),
        info={
            'colanderalchemy': {
                'typ': AmountType(5),
                'title': 'Montant',
                'missing': colander.required,
            }
        },
    )
    tva = Column(Integer,
                 nullable=False,
                 default=196,
                 info={
                     "colanderalchemy": {
                         "typ":
                         AmountType(2),
                         "validator":
                         forms.get_deferred_select_validator(Tva,
                                                             id_key='value'),
                         "missing":
                         colander.required
                     }
                 })
    task = relationship(
        "Task",
        uselist=False,
        info={'colanderalchemy': forms.EXCLUDED},
    )

    def __json__(self, request):
        return dict(
            id=self.id,
            task_id=self.task_id,
            description=self.description,
            amount=integer_to_amount(self.amount, 5),
            tva=integer_to_amount(self.tva, 2),
        )

    def duplicate(self):
        """
            return the equivalent InvoiceLine
        """
        line = DiscountLine()
        line.tva = self.tva
        line.amount = self.amount
        line.description = self.description
        return line

    def __repr__(self):
        return u"<DiscountLine amount : {s.amount} tva:{s.tva} id:{s.id}>"\
            .format(s=self)
Example #9
0
class TaskLine(DBBASE, LineCompute):
    """
        Estimation/Invoice/CancelInvoice lines
    """
    __colanderalchemy_config__ = {
        'validator': tva_product_validator,
        'after_bind': taskline_after_bind,
    }
    __table_args__ = default_table_args
    id = Column(
        Integer,
        primary_key=True,
        info={'colanderalchemy': {
            'widget': deform.widget.HiddenWidget()
        }})
    group_id = Column(Integer,
                      ForeignKey('task_line_group.id', ondelete="cascade"),
                      info={'colanderalchemy': forms.EXCLUDED})
    order = Column(
        Integer,
        default=1,
    )
    description = Column(
        Text,
        info={
            'colanderalchemy': {
                'widget':
                deform.widget.RichTextWidget(options={
                    'language':
                    "fr_FR",
                    'content_css':
                    "/fanstatic/fanstatic/css/richtext.css",
                }, ),
                'validator':
                forms.textarea_node_validator,
            }
        },
    )
    cost = Column(
        BigInteger(),
        info={
            'colanderalchemy': {
                'typ': AmountType(5),
                'title': 'Montant',
                'missing': colander.required,
            }
        },
        default=0,
    )
    quantity = Column(Float(),
                      info={
                          'colanderalchemy': {
                              "title": u"Quantité",
                              'typ': QuantityType(),
                              'missing': colander.required,
                          }
                      },
                      default=1)
    unity = Column(
        String(100),
        info={
            'colanderalchemy': {
                'title':
                u"Unité",
                'validator':
                forms.get_deferred_select_validator(
                    WorkUnit,
                    id_key='label',
                ),
                'missing':
                colander.drop,
            }
        },
    )
    tva = Column(Integer,
                 info={
                     'colanderalchemy': {
                         'typ':
                         AmountType(2),
                         'title':
                         'Tva (en %)',
                         'validator':
                         forms.get_deferred_select_validator(Tva,
                                                             id_key='value'),
                         'missing':
                         colander.required
                     }
                 },
                 nullable=False,
                 default=2000)
    product_id = Column(Integer,
                        info={
                            'colanderalchemy': {
                                'validator':
                                forms.get_deferred_select_validator(Product),
                                'missing':
                                colander.drop,
                            }
                        })
    group = relationship(TaskLineGroup,
                         primaryjoin="TaskLine.group_id==TaskLineGroup.id",
                         info={'colanderalchemy': forms.EXCLUDED})
    product = relationship("Product",
                           primaryjoin="Product.id==TaskLine.product_id",
                           uselist=False,
                           foreign_keys=product_id,
                           info={'colanderalchemy': forms.EXCLUDED})

    def duplicate(self):
        """
            duplicate a line
        """
        newone = TaskLine()
        newone.order = self.order
        newone.cost = self.cost
        newone.tva = self.tva
        newone.description = self.description
        newone.quantity = self.quantity
        newone.unity = self.unity
        newone.product_id = self.product_id
        return newone

    def gen_cancelinvoice_line(self):
        """
            Return a cancel invoice line duplicating this one
        """
        newone = TaskLine()
        newone.order = self.order
        newone.cost = -1 * self.cost
        newone.tva = self.tva
        newone.description = self.description
        newone.quantity = self.quantity
        newone.unity = self.unity
        newone.product_id = self.product_id
        return newone

    def __repr__(self):
        return u"<TaskLine id:{s.id} task_id:{s.group.task_id} cost:{s.cost} \
 quantity:{s.quantity} tva:{s.tva}>".format(s=self)

    def __json__(self, request):
        result = dict(
            id=self.id,
            order=self.order,
            cost=integer_to_amount(self.cost, 5),
            tva=integer_to_amount(self.tva, 2),
            description=self.description,
            quantity=self.quantity,
            unity=self.unity,
            group_id=self.group_id,
        )
        if self.product_id is not None:
            result['product_id'] = self.product_id
        return result

    @property
    def task(self):
        return self.group.task

    @classmethod
    def from_sale_product(cls, sale_product):
        """
        Build an instance based on the given sale_product

        :param obj sale_product: A SaleProduct instance
        :returns: A TaskLine instance
        """
        result = cls()
        result.description = sale_product.description
        result.cost = amount(sale_product.value, 5)
        result.tva = sale_product.tva
        result.unity = sale_product.unity
        result.quantity = 1
        return result
Example #10
0
class BaseExpenseLine(DBBASE, PersistentACLMixin):
    """
        Base models for expense lines
        :param type: Column for polymorphic discrimination
        :param date: Date of the expense
        :param description: description of the expense
        :param code: analytic code related to this expense
        :param valid: validation status of the expense
        :param sheet_id: id of the expense sheet this expense is related to
    """
    __tablename__ = 'baseexpense_line'
    __table_args__ = default_table_args
    __mapper_args__ = dict(
        polymorphic_on="type",
        polymorphic_identity="line",
        with_polymorphic='*',
    )
    id = Column(
        Integer,
        primary_key=True,
        info={"colanderalchemy": forms.EXCLUDED},
    )
    type = Column(
        String(30),
        nullable=False,
        info={'colanderalchemy': forms.EXCLUDED},
    )
    date = Column(
        Date(),
        default=datetime.date.today,
        info={'colanderalchemy': {
            'title': u"Date"
        }},
    )
    description = Column(
        String(255),
        info={'colanderalchemy': {
            'title': u"Description"
        }},
        default="",
    )
    category = Column(Enum('1', '2', name='category'), default='1')
    valid = Column(Boolean(),
                   default=True,
                   info={"colanderalchemy": {
                       "title": u"Valide ?"
                   }})

    type_id = Column(Integer,
                     info={
                         'colanderalchemy': {
                             'validator':
                             forms.get_deferred_select_validator(ExpenseType),
                             'missing':
                             colander.required,
                             "title":
                             u"Type de dépense",
                         }
                     })

    sheet_id = Column(Integer,
                      ForeignKey("expense_sheet.id", ondelete="cascade"),
                      info={'colanderalchemy': forms.EXCLUDED})

    type_object = relationship(
        "ExpenseType",
        primaryjoin='BaseExpenseLine.type_id==ExpenseType.id',
        uselist=False,
        foreign_keys=type_id,
        info={'colanderalchemy': forms.EXCLUDED})

    def __json__(self, request):
        return dict(
            id=self.id,
            date=self.date,
            description=self.description,
            category=self.category,
            valid=self.valid,
            type_id=self.type_id,
            sheet_id=self.sheet_id,
        )